/* 一、移动 缩放 旋转 */
UIButton *btn = [[UIButton alloc]init];
btn.transform = CGAffineTransformTranslate(btn.transform, 100, 100);
btn.transform = CGAffineTransformScale(btn.transform, 100, 100);
btn.transform = CGAffineTransformRotate(btn.transform, 3);
/* 二、数据晚加载 */
- (NSArray *)imageData
{
if (_imagaData == nil) {
//初始化数据
}
return _imageData;
}
/* 三、需要延迟执行的函数 */
[self performSelector:@selector(delay:) withObject:nil afterDelay:5.0];
//或者
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//需要延迟执行的代码
});
/* 四、修改属性最好加上状态值 */
UIButton *btn = [[UIButton alloc]init];
//btn.titleLabel.text = @"btn";//没有状态值可能会导致混乱
[btn setTitle:@"btn" forState:UIControlStateNormal];
/* 五、模型的初始化方式 */
- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init]) {
self.name = dict[@"name"];
self.icon = dict[@"icon"];
}
return self;
}
+ (instancetype)appWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}//instancetype只能用在返回值类型上,不能像id一样用在参数类型上;并且编译器会检测instancetype的真实类型
/* 六、遍历数组元素执行某方法 */
NSMutableArray *views;
for (UIView *subView in views) {
[subView removeFromSuperview];
}
或:
[views makeObjectsPerformSelector:@selector(removeFromSuperview)];
iOS初学知识总结
最新推荐文章于 2024-09-01 16:14:06 发布