如何在Xib中设置Button的属性
展开全部
1.设置圆角
直接在xib文件所对应的类的.m文件中重写- (void)drawRect:(CGRect)rect方法:
- (void)drawRect:(CGRect)rect{
[super drawRect:rect];
self.playerBtn.layer.cornerRadius = 3.0;
self.playerBtn.layer.masksToBounds = YES;
}
2.设置背景颜色(不是背景图片)
[self.playerBtn setBackgroundImage:[UIImage imageWithColor:RGBA(0, 127, 180, 1.0)] forState:UIControlStateNormal];
[self.playerBtn setBackgroundImage:[UIImage imageWithColor:RGBA(171, 77, 197, 1.0)] forState:UIControlStateHighlighted];
+ (UIImage*) imageWithColor: (UIColor*) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
这里的+ (UIImage*) imageWithColor: (UIColor*) color方法是我定义在UIImage+ImageEffects类目中的一个方法
直接在xib文件所对应的类的.m文件中重写- (void)drawRect:(CGRect)rect方法:
- (void)drawRect:(CGRect)rect{
[super drawRect:rect];
self.playerBtn.layer.cornerRadius = 3.0;
self.playerBtn.layer.masksToBounds = YES;
}
2.设置背景颜色(不是背景图片)
[self.playerBtn setBackgroundImage:[UIImage imageWithColor:RGBA(0, 127, 180, 1.0)] forState:UIControlStateNormal];
[self.playerBtn setBackgroundImage:[UIImage imageWithColor:RGBA(171, 77, 197, 1.0)] forState:UIControlStateHighlighted];
+ (UIImage*) imageWithColor: (UIColor*) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
这里的+ (UIImage*) imageWithColor: (UIColor*) color方法是我定义在UIImage+ImageEffects类目中的一个方法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询