// .h
@property (strong, nonatomic) IBOutlet UIImageView *logoImageView;
// .m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x / 2, self.view.frame.origin.y / 2, 32, 32)];
[self.logoImageView setImage:[UIImage imageNamed:@"logo"]];
CALayer *lay = self.logoImageView.layer;
// 发挥作用的两个设置
[lay setMasksToBounds:YES];
[lay setCornerRadius:16]; // 正方形边长的一半
[self.view addSubview:self.logoImageView];
}
Last active
August 29, 2015 14:01
-
-
Save JeOam/80eac4bc5a9a17b66da5 to your computer and use it in GitHub Desktop.
UIImageView template
每个UIView对象都有一个layer属性,这个layer属性实际上是一个CALayer对象。这个对象负责把UIView对象显示到屏幕上。而layer则有一个cornerRadius属性,用来指定layer的边框圆角。但是光设定这个属性是不够的,因为layer默认会把图像超出边框的部分也显示出来,所以必须指定masksToBounds属性为YES,让layer切掉边框外的部分。最终实现了图像的圆角显示。
via here
图片拉伸:resizableImageWithCapInsets
// Creates and returns a new image object with the specified cap insets.
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
其中Insets这个参数的格式是(top,left,bottom,right),从上、左、下、右分别在图片上画了一道线,这样就给一个图片加了一个框。只有在框里面的部分才会被拉伸,而框外面的部分则不会改变。
via here
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UITapGestureRecognizer