订制IOS系统控件要注意的问题
通常在定制系统控件时,一般要遍历控件内的subviews,如下在定制UIAlertView时
[html]
-(void)willPresentAlertView:(UIAlertView *)alertView{
for (UIView* view in [alertView subviews])
{
//判断如果是UILabel
if ([[[view class] description] isEqualToString:@"UILabel"])
{
//针对UILabel做定制操作
}
//判断如果是UIButton
if ([[[view class] description] isEqualToString:@"UIAlertButton"]
|| [[[view class] description] isEqualToString:@"UIThreePartButton"])
{
//针对UIButton做定制操作
}
}
}
使用 [[[view class] description] isEqualToString:@"UIAlertButton"] 方法判断当前View是不是一个按钮时,有个弊端,因为[[view class] description]在不同的设备上有不同的描述,所以在以上的方法中使用了UIAlertButton或者UIThreePartButton,当然甚至还有更多。
其实完全不需要这样判断,可以使用[view isKindOfClass:NSClassFromString(@"UIButton")]来判断,也不用区分不同的设备,修改后的方法如下:
[html]
-(void)willPresentAlertView:(UIAlertView *)alertView{
for (UIView* view in [alertView subviews])
{
//判断如果是UILabel
if ([view isKindOfClass:NSClassFromString(@"UILabel")])
{
//针对UILabel做定制操作
}
//判断如果是UIButton
if ([view isKindOfClass:NSClassFromString(@"UIButton")])
{
//针对UIButton做定制操作
}
}
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- ios开发问题:添加库和复制其它工程文件编译错误问题
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- iphone开发之object c基础一定义接口
- Lexical or Preprocessor Issue 'xxx.h
- iPhone应用开发之十一:常用的三种动画表现效果
- Memory on the iPhone
- iPhone开发学习笔记006—— NSNotification自定义通知名
- Android:实现TabWidget选项卡按钮在屏幕下方
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- 多线程之NSInvocationOperation