您的位置:首页 > 其它

总结的一些简单实用的小方法

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: