Xcode / Swift |将TopBorder添加到TabBar

时间:2018-11-03 19:06:03

标签: swift xcode uitabbarcontroller tabbar

基本上,到目前为止,我得到的是带有自定义图标的基本TabBarController。现在,我想只在TabBar的顶部尽可能简单地添加带有特定UIColor的边框。我怎么做? My tabBar so far

1 个答案:

答案 0 :(得分:0)

配置标签栏,如下所示:-

// Create a new layer which is the width of the device and with a heigh
// of 0.5px.
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 0.5f);

// Set the background colour of the new layer to the colour you wish to
// use for the border.
topBorder.backgroundColor = [[UIColor blueColor] CGColor];

// Add the later to the tab bar's existing layer
[self.tabBar.layer addSublayer:topBorder];
self.tabBar.clipsToBounds = YES;

子类化选项卡栏并将其写在此处,或将其写为全局函数。