gpt4 book ai didi

ios - 更改标签栏的高度和宽度并添加圆角

转载 作者:行者123 更新时间:2023-11-28 11:02:44 29 4
gpt4 key购买 nike

我想知道是否可以更改宽度和高度并为标签栏添加圆角?

大致是这样的:

我想把tab bar变小,加圆角。

我现在可以用这样的东西改变尺寸:

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: enter image description here

2- 创建自定义 uitabbarController 类并将该代码放入 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;
}

结果是这样的:

enter image description here

如果还是不清楚,我给你做了一个xcode工程,上传到github上了,大家可以根据自己的需要随意使用:)

Custom UITabBarController by Sdiri Houssem on Github

最好的问候

关于ios - 更改标签栏的高度和宽度并添加圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925733/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com