UITabBarItem 更改图像的高度和宽度/UINavigationBar 更改样式

从苹果文档的最大大小的一张图片在 TabBar 是 30 x 30 (60 x 60 的视网膜显示器)。

我不认为它是可能采取整个 TabBar 不拉伸图像的高度。我认为最好的解决办法是中心中使用 imageInset TabBar 的图像

tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

enter image description here

否则你可以玩这 imageInset 和拉伸图像像在截图中

tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);

enter image description here

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  {


 UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

 UITabBar *tabBar = tabBarController.tabBar;
 UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
 UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
 UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];

 //add image to tabbarItems

 tabBarItem1.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);
}

 [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

    NSShadow *shadow = [[NSShadow alloc] init];

    shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];

    shadow.shadowOffset = CGSizeMake(0, 1);

    // [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0]

    [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:

                                                           [UIColor grayColor], NSForegroundColorAttributeName,

                                                           shadow, NSShadowAttributeName,

                                                           [UIFont fontWithName:@"Avenir-Medium"  size:20.0], NSFontAttributeName, nil]];


 UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithImage:[self scaleImageToSize:[UIImage imageNamed:@"ico_location_up"size:CGSizeMake(20, 26)] style:UIBarButtonItemStyleBordered target:self action:@selector(do)];

    self.navigationItem.leftBarButtonItem = cameraItem;


//修改图片大小和控件一致

- (UIImage *)scaleImageToSize:(UIImage *)img size:(CGSize)size

{

    UIGraphicsBeginImageContext(size);

    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];

    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return scaledImage;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值