【发布时间】:2011-01-11 09:44:48
【问题描述】:
我想为我项目中的所有 UIImageView 添加一些圆角。我已经让代码工作了,但我必须将它应用到每张图片上;我应该继承 UIImageView 来添加这个吗?如果是这样,有人可以给我一些关于如何做到这一点的指示吗?
这里是代码
- (void)viewDidLoad {
[super viewDidLoad];
NSString *mainpath = [[NSBundle mainBundle] bundlePath];
welcomeImageView.image = [UIImage imageWithContentsOfFile:[mainpath stringByAppendingString:@"/test.png"]];
welcomeImageView.layer.cornerRadius = 9.0;
welcomeImageView.layer.masksToBounds = YES;
welcomeImageView.layer.borderColor = [UIColor blackColor].CGColor;
welcomeImageView.layer.borderWidth = 3.0;
CGRect frame = welcomeImageView.frame;
frame.size.width = 100;
frame.size.height = 100;
welcomeImageView.frame = frame;
}
【问题讨论】:
-
嗨,杰克 - 谢谢你,这正是我想做的。当我尝试使用它时,我收到一个错误“访问属性的未知 'cornerRadius' 组件”,对于 maskToBounds 等也是如此。奇怪的是,xcode 中的代码感知功能有助于为我填充这些属性,但编译器不会编译它们。上面的代码在 iOS4.0 上对你有用吗?
-
你需要#import
标签: ios subclass code-reuse objective-c-category