作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 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)
}
这是输出
关于ios - 如何仅在圆形 UIButton 顶部制作边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37788427/
我是一名优秀的程序员,十分优秀!