iOS - 利用UILayer实现扁平化控件、带弧度的UIButton、圆形的UIImageView:

最近在做扁平化,需要修改一些控件,因为是纯代码,没法在 xib文件里面拖,实现之后记录一下:


UIButton 

    UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnLogin.frame = CGRectMake(30.0, 275.0, 260.0, 45.0);
    [btnLogin setBackgroundColor:[UIColor colorWithRed:73.0/255.0 green:189.0/255.0 blue:204.0/255.0 alpha:1.0]];
    btnLogin.layer.cornerRadius = 4.0;
    btnLogin.titleLabel.font = ZY_FONT(17.0);
    [btnLogin setTitle:NSLocalizedString(@"ok", nil) forState:UIControlStateNormal];
    [btnLogin setTintColor:[UIColor whiteColor]];
    [btnLogin addTarget:self action:@selector(changePw:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnLogin];
iOS - 利用UILayer实现扁平化控件、带弧度的UIButton、圆形的UIImageView:_第1张图片


UIImageView

                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1.0, 5.0, 60.0, 60.0)];
                imageView.layer.cornerRadius = imageView.frame.size.height/2;
                imageView.layer.masksToBounds = YES;
                [imageView setContentMode:UIViewContentModeScaleAspectFill];
                [imageView setClipsToBounds:YES];
                imageView.layer.shadowColor = [UIColor whiteColor].CGColor;
                imageView.layer.shadowOffset = CGSizeMake(4.0, 4.0);
                imageView.layer.shadowOpacity = 0.5;
                imageView.layer.shadowRadius = 2.0;
                imageView.layer.borderColor = [UIColor whiteColor].CGColor;
                imageView.layer.borderWidth = 2.0f;
                imageView.image = [UIImage imageNamed:@"profileIcon.png"];
                [cell.contentView addSubview:imageView];

iOS - 利用UILayer实现扁平化控件、带弧度的UIButton、圆形的UIImageView:_第2张图片

你可能感兴趣的:(UIButton,控件,UIImageView,UILayer,圆形弧角)