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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 15:22   27   0

从苹果文档的最大大小的一张图片在 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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP