ios 重用UI部分代码的好方法(再也不用为局部变量的命名而烦恼啦!)
2013-07-09 14:56
603 查看
重用控件类代码的一个非常好的解决方案:所有一样的控件其名字均用同样的一个名字。只是在最后赋值的时候,将创建好的控件赋给我们需要用到的那个控件。 - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UIColor *)textColor { if((self = [super initWithFrame:frame])) { self.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)]; label.autoresizingMask = UIViewAutoresizingFlexibleWidth; label.font = [UIFont systemFontOfSize:12.0f]; label.textColor = textColor; label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; label.shadowOffset = CGSizeMake(0.0f, 1.0f); label.backgroundColor = [UIColor clearColor]; label.textAlignment = UITextAlignmentCenter; [self addSubview:label]; _lastUpdatedLabel=label; [label release]; label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)]; label.autoresizingMask = UIViewAutoresizingFlexibleWidth; label.font = [UIFont boldSystemFontOfSize:13.0f]; label.textColor = textColor; label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; label.shadowOffset = CGSizeMake(0.0f, 1.0f); label.backgroundColor = [UIColor clearColor]; label.textAlignment = UITextAlignmentCenter; [self addSubview:label]; _statusLabel=label; [label release];
相关文章推荐
- iOS 常用UI 部分常用 方法
- 通过定义BaseActivity来实现项目中代码重用,重写setContentView实现多个Activity部分UI布局相同
- IOS开发中UI部分UIWebView简单使用<代码演示>
- 《Effective Objective-C 2.0:编写高质量iOS与OS X代码的52个有效方法》阅读笔记
- iOS 中UI部分一些类的继承关系
- iOS开发学习之UI篇2、AppDelegate.m文件中方法的主要功能
- iOS UI-(多)视图控制器的生命周期、加载方法和模态视图方法以及屌丝方法
- 编写高质量iOS与OS X代码的52个有效方法
- iOS UIApplication的代理方法总结
- iOS-不用ID的打包方法
- VS 应用中,部分文件中的代码无法折叠的处理方法(以ashx文件为例)
- [IOS_UI控件] IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- iOS - 重写set和get方法后,为什么使用时会发生无效?解析命名规范
- iOS项目的完整重命名方法图文教程
- [编写高质量iOS代码的52个有效方法](二)对象
- Effective Object_C 2.0 编写高质量ios与OS X代码的52个有效方法之一
- 代码手写UI,xib和StoryBoard间的博弈(IOS)
- ios-day10-03(省份和城市联动。UIPickerView的使用、使用UIPickerView的reloadComponent:方法刷新某一列)
- 提高Java代码重用性方法 措施二:把参数类型改成接口
- iOS项目的总代码行数的方法