【iOS】添加圆角的方法、添加阴影

添加圆角(一)

viewObj.layer.cornerRadius = 5.0;                                                               
viewObj.layer.masksToBounds = YES;

添加圆角(二)

在该对象的drawRect方法中中加上

- (void)drawRect:(CGRect)rect {
    CGFloat cornerRadius = 8.0;                                      
    CGFloat width = rect.size.width;
    CGFloat height = rect.size.height;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
    [path addClip];
}

添加阴影

    self.logoutButton.layer.shadowOffset = CGSizeMake(0, 10);
    self.logoutButton.layer.shadowColor = [UIColor redColor].CGColor;
    self.logoutButton.layer.shadowOpacity = 1;

你可能感兴趣的:(【iOS】添加圆角的方法、添加阴影)