开发随笔 - 常用属性、方法

  • 导航栏透明:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

[self.navigationController.navigationBar setShadowImage:[UIImage new]];
  • 隐藏无内容cell
myTableView.tableFooterView = [[UIView alloc] init];
  • 去掉cell的点击状态
[myCell setSelectionStyle:UITableViewCellSelectionStyleNone];
  • cell的分割线
myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;(样式) myTableView.separatorColor = [UIColor grayColor];(颜色)
myTableView.separatorInset = UIEdgeInsetsMake(0,5, 0, 0);(距离上下左右)
  • cell右侧小箭头
myCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  • 点击self.view收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
  • 给button的title加下滑线
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中奖记录"];
NSRange strRange = {0,[str length]};  
[str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];  
[_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal];
  • label不同颜色
 NSMutableAttributedString *attributeMyPriceStr = [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@"价格:%@元/小时",[dictonary objectForKey:@"myPrice"]]];
    NSUInteger myPriceLength = [NSStringstringWithFormat:@"%@",[dictonary objectForKey:@"myPrice"]].length;
    [attributeMyPriceStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(3, myPriceLength+4)];
    _parkPriceLabel.attributedText = attributeMyPriceStr;
  • push到下一个界面是,有个过渡的阴影,怎么解决?跳转之前设一下下个页面的背景颜色

  • 去掉返回箭头的title

UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
      backItem.title=@"";
self.navigationItem.backBarButtonItem = backItem;

或者:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
 forBarMetrics:UIBarMetricsDefault];
  • ScrollView 的contentsize.height=0即可禁止上下滚动
    同理contentsize.width =0即可禁止左右滚动。但是7.0系统之后为什么有时候不起效果呢?
    因为 如果一个控制器中出现两个以上的UIScrollView(包括其子类),automaticallyAdjustsScrollViewInsets这个属性需要设置为NO.即不会预留空白。(7.0之后默认是YES)

  • 在不缩放图片,不去掉title的前提下,替换backBarButton图片的方法:(原理很简单,第一行加载图片,第二行以加载图片的宽度结合resizableImageWithCapInsets生成一个缩放时不会拉伸的新图片作为BackButtonBackgroundImage,再在第三行设置title的位置偏移到一个不可见的位置,达到隐藏的目的。另外,如果需要全部统一替换,也可以在app的didFinishLaunching里通[UIBarButtonItem appearance]全部统一替换!)

UIImage* image = [UIImage imageNamed:@"back_button.png"];

[item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[item setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault];

self.navigationItem.backBarButtonItem = item;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值