更改标签栏的高度和宽度并添加圆角
Change tab bar height and width and add rounded corners
我想知道是否可以更改宽度和高度并为标签栏添加圆角?
大致是这样的:
我想把标签栏变小,加圆角。
我现在可以用这样的东西改变大小:
override func viewWillLayoutSubviews() {
var tabFrame = self.tabBar.frame
// - 40 is editable , the default value is 49 px, below lowers the tabbar and above increases the tab bar size
tabFrame.size.height = 40
tabFrame.origin.y = self.view.frame.size.height - 40
self.tabBar.frame = tabFrame
}
但是实现图像设计的最佳方法是什么?
提前致谢
更改标签栏可能导致您在应用审核方面遇到麻烦。
为了更容易定制,请尝试使用自定义标签栏控件。
查看 Here 可轻松完全自定义的选项卡栏组件的开源列表。
告诉我这是否解决了您的问题,否则我们可以进行进一步的定制。
编辑:
好吧,这是你需要做的:
1-为背景创建一个圆形透明png:
2- 创建自定义 uitabbarController class 并将该代码放入 ViewDidLoad:
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
UIImage *image = [self imageWithImage:[UIImage imageNamed:@"circle.png"]scaledToSize:CGSizeMake(self.tabBar.frame.size.height+1, self.tabBar.frame.size.height+1)];
UIEdgeInsets edgeInsets;
edgeInsets.left = image.size.width/2;
edgeInsets.top = 0.0f;
edgeInsets.right = image.size.width/2; //this will be the constant portion in your image
edgeInsets.bottom = 0.0f;
image = [image resizableImageWithCapInsets:edgeInsets];
[[UITabBar appearance] setBackgroundImage:image];
使用此方法调整图像大小以适合 UITabBar 高度:
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
结果如下所示:
如果还有不明白的地方,我给你做了一个xcode项目上传到github,请随意使用它来满足你的需要:)
Custom UITabBarController by Sdiri Houssem on Github
此致
我想知道是否可以更改宽度和高度并为标签栏添加圆角?
大致是这样的:
我想把标签栏变小,加圆角。
我现在可以用这样的东西改变大小:
override func viewWillLayoutSubviews() {
var tabFrame = self.tabBar.frame
// - 40 is editable , the default value is 49 px, below lowers the tabbar and above increases the tab bar size
tabFrame.size.height = 40
tabFrame.origin.y = self.view.frame.size.height - 40
self.tabBar.frame = tabFrame
}
但是实现图像设计的最佳方法是什么?
提前致谢
更改标签栏可能导致您在应用审核方面遇到麻烦。 为了更容易定制,请尝试使用自定义标签栏控件。
查看 Here 可轻松完全自定义的选项卡栏组件的开源列表。
告诉我这是否解决了您的问题,否则我们可以进行进一步的定制。
编辑:
好吧,这是你需要做的:
1-为背景创建一个圆形透明png:
2- 创建自定义 uitabbarController class 并将该代码放入 ViewDidLoad:
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
UIImage *image = [self imageWithImage:[UIImage imageNamed:@"circle.png"]scaledToSize:CGSizeMake(self.tabBar.frame.size.height+1, self.tabBar.frame.size.height+1)];
UIEdgeInsets edgeInsets;
edgeInsets.left = image.size.width/2;
edgeInsets.top = 0.0f;
edgeInsets.right = image.size.width/2; //this will be the constant portion in your image
edgeInsets.bottom = 0.0f;
image = [image resizableImageWithCapInsets:edgeInsets];
[[UITabBar appearance] setBackgroundImage:image];
使用此方法调整图像大小以适合 UITabBar 高度:
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
结果如下所示:
如果还有不明白的地方,我给你做了一个xcode项目上传到github,请随意使用它来满足你的需要:)
Custom UITabBarController by Sdiri Houssem on Github
此致