天天看點

一些常用的代碼

1. 為image view、label等元件添加動作

UIImageView *imgView = [[UIImageView alloc] init];

UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget: self                                         action: @selector(imageViewClicked:)];

gesture.numberOfTouchesRequired = 1;

gesture.numberOfTapsRequired = 1;

[imgView addGestureRecognizer: gesture];

2. 擷取一個執行個體的類名

Class cla = [imgView class];

NSString *des = [cla description];

3. UIToolBar支援blur(毛玻璃)效果,如果不想用開源代碼,其實可以直接把toolbar當作view來用

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

toolbar.barStyle = UIBarStyleBlackTranslucent;

toolbar.translucent = YES;

4. 擷取某個cell目前的origin.y

NSIndexPath *indexPath = [NSIndexPath indexPathForRow: btn.tag inSection: 0];

CGRect cellRect = [self.tableView rectForRowAtIndexPath: indexPath];

float y = cellRect.origin.y - self.tableView.contentOffset.y;