1、继承UIButton自定义button
2、在.h中添加
@property(nonatomic,assign) CGRect titleRect;
@property(nonatomic,assign) CGRect imageRect;
属性。
3、在.m中添加
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
return self.imageRect;
}
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
return self.titleRect;
}
两个方法;4、搞定。
本文详细介绍了如何继承 UIButton 来自定义按钮,并通过添加 titleRect 和 imageRect 属性来实现按钮外观的定制。同时,展示了如何在 .m 文件中实现获取这些属性的方法。

被折叠的 条评论
为什么被折叠?



