一些常用的代码

来源:互联网 发布:网络系统集成中的软件 编辑:程序博客网 时间:2024/06/06 03:24

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: [[UIScreenmainScreen]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;


0 0
原创粉丝点击