总结的一些简单实用的小方法
2017-03-20 11:39
232 查看
1.self.navigationController.navigationBar.subviews[0].alpha = 0 设置导航栏为透明
2. flashScrollIndicators
这个很有用,闪一下滚动条 ,暗示是否有可滚动的内容,可在ViewDidAppear [table reload] 之后调用
3.点击cell上的按钮时,获取所在的cell
-(void)OnTouchBtnInCell:(UIButton *)btn {
CGPoint point = btn.center;
point = [table convertPoint:point fromView:btn.superview];
NSIndexPath* indexpath = [table indexPathForRowAtPoint:point];
UITableViewCell *cell = [table cellForRowAtIndexPath:indexpath];
}
4.someview 显示一段时间后自动消失
[self performSelector:@selector(dismissView:) withObject:someview afterDelay:2];
5. UINavigationBar (selBackground)
-(void)setToCustomImage {
if ([[UIDevice currentDevice] systemVersion].floatValue >= 5.0 ) { [self setBackgroundImage:[UIImage imageNamed:@"navBar"] forBarMetrics:UIBarMetricsDefault];
} else {
self.layer.contents = (id)[UIImage imageNamed:@"navBar"].CGImage;
}
}
6.把导航条底部的横线去掉
[self.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
7.配合runtime,类别上是可以加属性的
objc_setAssociatedObject(self, @"string", string, OBJC_ASSOCIATION_COPY_NONATOMIC);
return objc_getAssociatedObject(self,@"string");
8.循环,遍历出数组
for (int i = 0; i < [titleStr length]; i++) {
int a = [titleStr characterAtIndex:i];
if (isdigit(a)) {
//让数字颜色改变
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(i, 1)];
}
}
//两行lable之间设置间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:20*SCALAE];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [titleStr length])];
9.自适应cell高度,可以返还CELL的高度(大概范围)
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100
2. flashScrollIndicators
这个很有用,闪一下滚动条 ,暗示是否有可滚动的内容,可在ViewDidAppear [table reload] 之后调用
3.点击cell上的按钮时,获取所在的cell
-(void)OnTouchBtnInCell:(UIButton *)btn {
CGPoint point = btn.center;
point = [table convertPoint:point fromView:btn.superview];
NSIndexPath* indexpath = [table indexPathForRowAtPoint:point];
UITableViewCell *cell = [table cellForRowAtIndexPath:indexpath];
}
4.someview 显示一段时间后自动消失
[self performSelector:@selector(dismissView:) withObject:someview afterDelay:2];
5. UINavigationBar (selBackground)
-(void)setToCustomImage {
if ([[UIDevice currentDevice] systemVersion].floatValue >= 5.0 ) { [self setBackgroundImage:[UIImage imageNamed:@"navBar"] forBarMetrics:UIBarMetricsDefault];
} else {
self.layer.contents = (id)[UIImage imageNamed:@"navBar"].CGImage;
}
}
6.把导航条底部的横线去掉
[self.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
7.配合runtime,类别上是可以加属性的
objc_setAssociatedObject(self, @"string", string, OBJC_ASSOCIATION_COPY_NONATOMIC);
return objc_getAssociatedObject(self,@"string");
8.循环,遍历出数组
for (int i = 0; i < [titleStr length]; i++) {
int a = [titleStr characterAtIndex:i];
if (isdigit(a)) {
//让数字颜色改变
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(i, 1)];
}
}
//两行lable之间设置间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:20*SCALAE];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [titleStr length])];
9.自适应cell高度,可以返还CELL的高度(大概范围)
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100
相关文章推荐
- 简单实用控制血压的一些小方法
- android剪切板一些简单实用方法
- UIAlertController的一些简单实用方法
- iOS开发中一些实用方法的总结
- 个人总结的一些JavaScript技巧、实用函数、简洁方法、编程细节
- 个人总结的一些JavaScript技巧、实用函数、简洁方法、编程细节
- UIGestureRecognizer的一些简单的方法总结
- Java集合框架collection各接口的实现类使用方法简单而实用的总结
- 简单又实用的不让Realplayer弹出广告补丁的方法
- web上的一些简单打印方法
- VC/MFC简单实用的全屏方法
- 简单实用的DataSet更新数据库的类+总结(c#)
- 字符串数组的一些处理方法总结
- 简单实用的DataSet更新数据库的类+总结(c#)
- 实用技巧:Linux截图与考屏方法总结
- 手工清除病毒的一些简单方法
- 一些搜集的实用方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- 向广大程序员推荐的简单实用的健身方法。
- 关系数据库的查询优化策略----总结了一些查询优化的方法,希望可以对大家有所帮助(原创)