如果文章对您有用,麻烦顺手点一下文章的广告吧~

东东

IOS几个视图的自定义设置
几个视图的自定义设置一、tabBar1.1、tabbar隐藏分割线///第一种 UITabBarControlle...
扫描右侧二维码阅读全文
26
2017/03

IOS几个视图的自定义设置

几个视图的自定义设置

一、tabBar

1.1、tabbar隐藏分割线

///第一种
UITabBarController *tableBarController = [[UITabBarController alloc] init];
[tableBarController.tabBar setBackgroundImage:[[UIImage alloc] init]];
[tableBarController.tabBar setShadowImage:[[UIImage alloc]init]];

1.2、tabbar设置背景图片

CGRect frame = CGRectMake(0, 0, JLXScreenSize.width, 60);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *img = [UIImage imageNamed:@"tab_bg"];
UIColor *color = [[UIColor alloc] initWithPatternImage:img];
v.backgroundColor = color;
[tableBarController.tabBar insertSubview:v atIndex:0];
tableBarController.tabBar.opaque = YES;

1.3、平板的图标填满

如果使用了自定义的视图,在iphone上面可以,但是图标在ipad错位,那就需要设置下tabbar的填充模式了,这样就能填满了

qOz5f.png

self.tabBar.itemPositioning = UITabBarItemPositioningFill;

二、navigationbar

2.1、设置头部标题

如果是navigationbar在UITabBarController上面的,设置头部标题和颜色

self.navigationController.navigationBar.topItem.title = @"我的简历";

如果只是push进去的navigationbar,设置头部标题则是

[self.navigationItem setTitle:@"完善简历资料"];

2.2、设置UIBarButtonItem

同理,设置UIBarButtonItem如果在navigationbar和UITabBarController嵌套的,则可使用

UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_data_custom"] style:UIBarButtonItemStyleDone target:self action:@selector(startCreateResume)];
self.navigationController.navigationBar.topItem.rightBarButtonItem = rightBarBtn;

如果是push进去的,则直接使用self.navigationItem.rightBarButtonItem即可

UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_data_custom"] style:UIBarButtonItemStyleDone target:self action:@selector(startCreateResume)];
self.navigationItem.rightBarButtonItem = rightBarBtn;

2.3、隐藏和显示

[self.navigationController setNavigationBarHidden:false];

2.4、设置隐藏分割线

[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

2.5、修改背景图片

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"back.png"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];  
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];  

其中back.png是宽一个像素,高为导航条高度的背景图片,这样即可达到效果

三、状态栏

3.1、设置状态栏颜色

info.plist中增加字段View controller-based status bar appearance,设置为NO

//设置为白色
[UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
//设置为黑色
[UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;

四、TableviewCell

4.1、设置cell的分割线颜色

[self.m_tableView setSeparatorColor:kJLXCellSeparatorColor];

五、button自定义

5.1、拉伸图片设置button

UIImage *clickImg = [UIImage imageNamed:@"btn_big_c"];
clickImg = [clickImg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 25) resizingMode:UIImageResizingModeStretch];
[createrButton setBackgroundImage:img forState:UIControlStateNormal];

通过设置img的拉伸范围来设置按钮。

5.2、设置button的点击效果

同样,可以单独通过img拉伸来设置点击状态

UIImage *img = [UIImage imageNamed:@"btn_big"];
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 25) resizingMode:UIImageResizingModeStretch];
UIImage *clickImg = [UIImage imageNamed:@"btn_big_c"];
clickImg = [clickImg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 25) resizingMode:UIImageResizingModeStretch];
[createrButton setBackgroundImage:img forState:UIControlStateNormal];
[createrButton setBackgroundImage:clickImg forState:UIControlStateHighlighted];

5.3、通过文字设置button

UIButton * button =[[UIButton alloc] init];
[button setTitle:@"开始制作" forState:UIControlStateNormal];
//设置字体
[button.titleLabel setFont:[UIFont systemFontOfSize:18]];
//设置颜色
[button setTitleColor:kJLXRedColor forState:UIControlStateNormal];
//设置字的内间距
[button setTitleEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
//设置button的圆角
button.layer.masksToBounds = true;
[button.layer setCornerRadius:40.0f*kJLXHeightScale];
[button.layer setBorderColor:kJLXRedColor.CGColor];
[button.layer setBorderWidth:1.0f];

[self.view addSubview:button];
//可以通过masonry设置大小和位置
[button mas_makeConstraints:^(MASConstraintMaker *make) {
      make.height.equalTo(@(80*kJLXHeightScale));
      make.width.equalTo(@(300*kJLXWidthScale));
      make.centerX.equalTo(self.view);
}];
Last modification:May 30th, 2017 at 08:52 am
如果觉得我的文章对你有用,请随意打赏: ☞已打赏列表

Leave a Comment