gpt4 book ai didi

ios - 如何仅在圆形 UIButton 顶部制作边框颜色?

转载 作者:行者123 更新时间:2023-11-28 12:46:56 24 4
gpt4 key购买 nike

我正在 UITabBarController 中制作一个中心圆 UIButton。我只需要在 UIButton 从 tabBar 边框出来的地方绘制边框颜色。我怎样才能做到?我们只需要边框颜色 https://monosnap.com/file/7MDqGzpUdIbClvnAvAiY2kJYKUro7z

我把 UIButton 做成了

       private func setupLifelineButton() {
let lifelineButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var lifelineButtonFrame = lifelineButton.frame
lifelineButtonFrame.origin.y = view.bounds.height - lifelineButtonFrame.height - 13 // default without 13
lifelineButtonFrame.origin.x = view.bounds.width / 2 - lifelineButtonFrame.size.width / 2
lifelineButton.frame = lifelineButtonFrame

// lifelineButton.backgroundColor = .redColor()
lifelineButton.layer.cornerRadius = lifelineButtonFrame.height / 2
lifelineButton.layer.borderWidth = 0.5
lifelineButton.layer.borderColor = ColorManager.tabBarLayerColor.CGColor//UIColor.blackColor().CGColor

lifelineButton.addTarget(self, action: #selector(menuButtonAction), forControlEvents: .TouchUpInside)

// icon

// lifelineButton.setImage(UIImage(named: "LifeLineBarButtonIcon"), forState: .Normal)

self.view.addSubview(lifelineButton)
self.view.layoutIfNeeded()
}

我需要去掉边框颜色的下半部分

最佳答案

这可能对你有帮助

objective-c

-(void)createCurveBtnWithBorder
{
UIBezierPath *shapePath = [UIBezierPath bezierPathWithRoundedRect:_btnCurve.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(_btnCurve.frame.size.width/2, _btnCurve.frame.size.height/2)];

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = _btnCurve.bounds;
shapeLayer.path = shapePath.CGPath;
_btnCurve.backgroundColor=[UIColor clearColor];
shapeLayer.fillColor = [UIColor purpleColor].CGColor;
shapeLayer.strokeColor = [UIColor blueColor].CGColor; //Here you can set border with green color
shapeLayer.lineWidth = 2;
[_btnCurve.layer addSublayer:shapeLayer];
}

swift 4

func createCurveBtnWithBorder()
{
let shapePath = UIBezierPath(roundedRect: btnCurve.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: btnCurve.frame.size.width / 2, height: btnCurve.frame.size.height / 2))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = btnCurve.bounds
shapeLayer.path = shapePath.cgPath
btnCurve.backgroundColor = UIColor.clear as? CGColor
shapeLayer.fillColor = UIColor.purple.cgColor
shapeLayer.strokeColor = UIColor.blue.cgColor
//Here you can set border with green color
shapeLayer.lineWidth = 2
btnCurve.layer.addSublayer(shapeLayer)
}

这是输出

enter image description here

关于ios - 如何仅在圆形 UIButton 顶部制作边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37788427/

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