美文网首页
传入颜色值生成纯色图片

传入颜色值生成纯色图片

作者: Fisher123 | 来源:发表于2018-03-21 18:17 被阅读3次
//通过传入颜色值生成纯色图片
- (UIImage *)imageWithBgColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

导航栏常用属性

1.导航栏背景色设置

self.navigationController.navigationBar.barTintColor = [UIColor greenColor];

2.导航栏标题颜色字体大小

NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
 attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];
[self.navigationController.navigationBar setTitleTextAttributes:attrs];

3.导航栏左右item

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStylePlain target:self action:@selector(left)];
self.navigationItem.leftBarButtonItem = leftItem;
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"right" style:UIBarButtonItemStylePlain target:self action:@selector(right)];   
self.navigationItem.rightBarButtonItem = rightItem;

4.导航栏item字体颜色

self.navigationController.navigationBar.tintColor = [UIColor redColor];
如果要不同item不同颜色,那么item要带一个自定义按钮,再设置按钮属性

5.当前控制器的下一个控制器的返回item去掉文字只保留箭头

 UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
  self.navigationItem.backBarButtonItem = backItem;

相关文章

网友评论

      本文标题:传入颜色值生成纯色图片

      本文链接:https://www.haomeiwen.com/subject/okqnqftx.html