相关疑难解决方法(0)

Swift - 角半径和投影的问题

我正在尝试创建一个带圆角投影的按钮.无论我如何切换,按钮都无法正确显示.我试过masksToBounds = falsemasksToBounds = 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 …
Run Code Online (Sandbox Code Playgroud)

shadow cornerradius ios swift xcode6

70
推荐指数
5
解决办法
7万
查看次数

UIBezierPath:如何在带圆角的视图周围添加边框?

我正在使用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
Run Code Online (Sandbox Code Playgroud)

当前

我想为此添加绿色边框,但我无法使用

myCell2.NewFeedImageView.layer.borderWidth = 8
myCell2.NewFeedImageView.layer.borderColor = UIColor.greenColor().CGColor
Run Code Online (Sandbox Code Playgroud)

因为它会切断边框的左上角和右上角,如下图所示:

问题

有没有办法添加UIBezierPath边框以及我当前的代码?

uibezierpath swift

17
推荐指数
3
解决办法
2万
查看次数

如何获取UIBezierPath的反向路径

self.myPath=[UIBezierPath bezierPathWithArcCenter:center 
                                           radius:200 
                                       startAngle:0 
                                         endAngle:180 
                                        clockwise:YES];
Run Code Online (Sandbox Code Playgroud)

(这让我能够通过一些网络搜索来运行起来).

我有这条路.现在我想填补这条路径的反面,所以留下这部分并填充其他所有内容.我怎样才能完成编码?我对此没有太多信息.

问题

在此输入图像描述

在使用Cemal之后它显示的区域之前它只显示了一个带红色笔划的圆圈.

编辑

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.punchedOutPath =  
         [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 400, 400)];
        self.fillColor = [UIColor redColor];
        self.alpha = 0.8;
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    [[self fillColor] set];
    UIRectFill(rect);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetBlendMode(ctx, kCGBlendModeDestinationOut);

    [[self punchedOutPath] fill];

    CGContextSetBlendMode(ctx, kCGBlendModeNormal);
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

iphone objective-c ios uibezierpath

13
推荐指数
3
解决办法
1万
查看次数

如何在iOS中简化单个复杂的UIBezierPath多边形

问题:

我有一个用户生成的多边形(通过在屏幕上注册用户的触摸),它可以是简单的或复杂的(复杂意味着具有未知数量的交叉点)并且我希望有一个简单的多边形由原始多边形上的相同点产生,类似于轮廓或轮廓,如果你愿意.

图片由堆栈溢出的未知用户提供

可能的解决方案:

我发现了这个,但它是一个JavaScript解决方案,是我需要的完美插图,但在ActionScript中!我不需要Path本身,这些点就足够了.你会怎么解决这个问题?

更新:

当我进一步观察时,我看到一些人建议解决方案是在点上使用凸壳算法,但是,凸壳不是这里的答案,因为如果我是对的,结果将如下:

凸壳重新组合

objective-c polygons ios uibezierpath

6
推荐指数
1
解决办法
2600
查看次数

掩盖UIView和自动布局

我有一个UIView,我想用另一个UIView掩盖,从中心打出一个洞.这是我的viewDidLoad:

- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.viewToMask];
[self.view addSubview:self.theMask];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.viewToMask attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.viewToMask attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[cyan(200)]" options:0 metrics:nil views:@{@"cyan": self.viewToMask}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[cyan(200)]" options:0 metrics:nil views:@{@"cyan": self.viewToMask}]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.theMask attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.viewToMask attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.theMask attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.viewToMask attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[mask(100)]" options:0 metrics:nil views:@{@"mask": self.theMask}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[mask(100)]" options:0 metrics:nil views:@{@"mask": self.theMask}]];
}
Run Code Online (Sandbox Code Playgroud)

它给了我正是我正在寻找的东西,减去掩蔽:

没有掩盖的观点

如果我再添加一行:

[self.viewToMask …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview ios autolayout

4
推荐指数
1
解决办法
5701
查看次数

Swift - 在阴影层切孔

我想在 UIView 和 Swift3、iOS 的阴影层中“切一个洞”

我有一个容器 (UIView),它有 2 个孩子:

  • 一个 UIImageView
  • 该图像顶部的一个 UIView(“叠加”)

我想给叠加一个阴影并切出该阴影的内部矩形,以在 ImageView 的边缘创建类似发光的效果
插入发光至关重要,因为图像占用了屏幕宽度
我的代码迄今为止:

let glowView = UIView(frame: CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight))
glowView.layer.shadowPath = UIBezierPath(roundedRect: container.bounds, cornerRadius: 4.0).cgPath
glowView.layer.shouldRasterize = true
glowView.layer.rasterizationScale = UIScreen.main.scale
glowView.layer.shadowOffset = CGSize(width: 1.0, height: 1.0)
glowView.layer.shadowOpacity = 0.4

container.addSubview(imageView)
container.addSubview(glowView)
Run Code Online (Sandbox Code Playgroud)

结果如下所示:

图片

现在我想剪掉较暗的内部部分,以便只保留边缘的阴影
任何想法如何实现?

shadow calayer ios swift swift3

2
推荐指数
1
解决办法
1045
查看次数