有没有办法cornerRadius只设置一个左上角和右上角UIView?
我尝试了以下内容,但最终没有看到视图了.
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
我试图将此Obj-C代码转换为Swift代码,但我不知道这段代码的等价物应该是什么?
#define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
我用Google搜索并找到了这个
但我不明白在我的情况下如何在Swift中转换它?
我正在尝试创建一个带圆角和投影的按钮.无论我如何切换,按钮都无法正确显示.我试过masksToBounds = false和masksToBounds = true,但无论是圆角半径工程和影子不或影子工程和圆角半径不夹按钮的角落.
import UIKit
import QuartzCore
@IBDesignable
class Button : UIButton
{
    @IBInspectable var masksToBounds: Bool    = false                {didSet{updateLayerProperties()}}
    @IBInspectable var cornerRadius : CGFloat = 0                    {didSet{updateLayerProperties()}}
    @IBInspectable var borderWidth  : CGFloat = 0                    {didSet{updateLayerProperties()}}
    @IBInspectable var borderColor  : UIColor = UIColor.clearColor() {didSet{updateLayerProperties()}}
    @IBInspectable var shadowColor  : UIColor = UIColor.clearColor() {didSet{updateLayerProperties()}}
    @IBInspectable var shadowOpacity: CGFloat = 0                    {didSet{updateLayerProperties()}}
    @IBInspectable var shadowRadius : CGFloat = 0                    {didSet{updateLayerProperties()}}
    @IBInspectable var shadowOffset …我试图创建一个ImageView圆角和阴影给它一些深度.我能够为它创建一个阴影UIImageView,但每当我添加代码也使它有圆角时,它只有圆角而没有阴影.我有一个IBOutlet名字myImage,它在viewDidLoad函数内部.有没有人对如何使其有效有任何想法?我究竟做错了什么?
override func viewDidLoad() {
    super.ViewDidLoad() 
    myImage.layer.shadowColor = UIColor.black.cgColor
    myImage.layer.shadowOpacity = 1 
    myImage.layer.shadowOffset = CGSize.zero
    myImage.layer.shadowRadius = 10
    myImage.layer.shadowPath = UIBezierPath(rect: myImage.bounds).cgPath
    myImage.layer.shouldRasterize = false
    myImage.layer.cornerRadius = 10
    myImage.clipsToBounds = true
}
我正在使用UIBezierPath让我的imageview有圆角,但我也想为imageview添加边框.请记住,顶部是uiimage,底部是标签.
目前使用此代码生成:
let rectShape = CAShapeLayer()
rectShape.bounds = myCell2.NewFeedImageView.frame
rectShape.position = myCell2.NewFeedImageView.center
rectShape.path = UIBezierPath(roundedRect: myCell2.NewFeedImageView.bounds,
    byRoundingCorners: .TopRight | .TopLeft,
    cornerRadii: CGSize(width: 25, height: 25)).CGPath
myCell2.NewFeedImageView.layer.mask = rectShape

我想为此添加绿色边框,但我无法使用
myCell2.NewFeedImageView.layer.borderWidth = 8
myCell2.NewFeedImageView.layer.borderColor = UIColor.greenColor().CGColor
因为它会切断边框的左上角和右上角,如下图所示:

有没有办法添加UIBezierPath边框以及我当前的代码?
我知道这个问题已经问过很多次了,他们的解决方案也可用,但对我来说没什么用.我正在使用Swift3,我想为了这个目的绕过UIView的任何两个方面我找到了以下解决方案
以下是我上述解决方案的代码片段
extension UIView {
    /**
     Rounds the given set of corners to the specified radius
     - parameter corners: Corners to round
     - parameter radius:  Radius to round to
     */
    func round(corners: UIRectCorner, radius: CGFloat) -> Void {
         layer.addSublayer(_round(corners: corners, radius: radius))
    }
    /**
     Rounds the given set of corners to the specified radius with a border
     - parameter corners:     Corners to round
     - parameter radius:      Radius to round to
     - parameter borderColor: The border color
     - parameter borderWidth: …ios ×5
swift ×4
cornerradius ×2
shadow ×2
uiview ×2
cocoa-touch ×1
macos ×1
macros ×1
objective-c ×1
swift3 ×1
uibezierpath ×1
uiimageview ×1
xcode6 ×1
xcode8 ×1