码迷,mamicode.com
首页 > 移动开发 > 详细

iOS--导航栏样式

时间:2017-01-09 18:52:24      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:tco   title   pre   iat   设置   code   ati   send   cal   

push返回按钮样式:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    [self.navigationItem setHidesBackButton:YES];

自由点击事件:

//用户协议跳转
    UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];
    
    // 2. 将点击事件添加到label上
    [self.UserRate addGestureRecognizer:labelTapGestureRecognizer];
    self.UserRate.userInteractionEnabled = YES; // 可以理解为设置label可被点击

创建左右导航栏按钮,搜索与个人中心:

//创建左右导航栏按钮,搜索与个人中心
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self scaleToSize:[UIImage imageNamed:@"sousuo.png"] size:CGSizeMake(20, 19.6)] style:UIBarButtonItemStylePlain target:self action:@selector(Actionleft:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self scaleToSize:[UIImage imageNamed:@"persons.png"] size:CGSizeMake(20, 20)] style:UIBarButtonItemStylePlain target:self action:@selector(Actionright:)];



//导航栏个人信息按钮
-(void)Actionright:(id)send{
    NSLog(@"跳转到个人中心页面");
    PersonalViewController *PersonalView = [self.storyboard instantiateViewControllerWithIdentifier:@"PersonalView"];
    [self.navigationController pushViewController:PersonalView animated:PersonalView];
}
//导航栏搜索按钮点击事件
-(void)Actionleft:(id)send{
    NSLog(@"跳转到搜索页面");
    SearchViewController *search = [self.storyboard instantiateViewControllerWithIdentifier:@"search"];
    [self.navigationController pushViewController:search animated:search];
    
}
//设置图片大小
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
     // 绘制改变大小的图片
    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
     // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
   // 使当前的context出堆栈
    UIGraphicsEndImageContext();
   // 返回新的改变大小后的图片
    return scaledImage;
}

 

iOS--导航栏样式

标签:tco   title   pre   iat   设置   code   ati   send   cal   

原文地址:http://www.cnblogs.com/qiyiyifan/p/6265899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!