ios中常用小技巧注意点

来源:互联网 发布:图像融合算法 编辑:程序博客网 时间:2024/05/29 02:33

1.设置图片原图显示

 UIImage*image=[UIImage imageNamed:@"place_map.png"];UIImage*original=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:original style:UIBarButtonItemStylePlain target:self action:@selector(locationPress)];

2.修改全局barButton渲染颜色 和字体样式

 UINavigationBar *navgationBar = [UINavigationBar appearance];    navgationBar.tintColor = [UIColor colorWithRed:0.61f green:0.61f blue:0.61f alpha:1.00f];    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:15],NSForegroundColorAttributeName:UIColorWithHexRGB(0xfe6d27)}];   [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:10],NSForegroundColorAttributeName : kRGBCOLOR(170,170,170)} forState:UIControlStateNormal]

3、隐藏tabbar

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {    viewController.hidesBottomBarWhenPushed = YES;    [super pushViewController:viewController animated:animated];    if (self.childViewControllers.count==1) {        viewController.hidesBottomBarWhenPushed = NO;    }}

4、TableView的Group样式中,默认的每个section都有sectionHeader和sectionFooter,只要调整这两个的大小就可以实现section之前的间距扩大或缩小

//tableview自带35距离self.tableView.contentInset = UIEdgeInsetsMake(-35,0,0,0);

5、获取label大小

textLabel.size = [textLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, textLabel.font.lineHeight)                                                  options:NSStringDrawingUsesLineFragmentOrigin                                               attributes:@{NSFontAttributeName : textLabel.font}                                                  context:nil].size;

6、tableviewcell让分割线从头开始

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath  {      if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {          [cell setSeparatorInset:UIEdgeInsetsZero];      }      if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {          [cell setLayoutMargins:UIEdgeInsetsZero];      }  }  

7、设置导航栏是否显示及改变状态栏文字颜色

- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    //设置状态栏字体为白色    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;    self.navigationController.navigationBar.hidden = YES;}- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];        //设置状态栏字体为黑色    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;    self.navigationController.navigationBar.hidden = NO;}
0 0
原创粉丝点击