小编Boo*_*oon的帖子

使用bezierPathWithOvalInRect绘制时边框被剪裁

我在我的自定义UIView的drawRect中绘制了一个圆圈:

- (void)drawRect:(CGRect)rect {
  ...
  UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect:rect];
  [UIColor.whiteColor setStroke];
  ovalPath.lineWidth = 1;
  [ovalPath stroke];
}
Run Code Online (Sandbox Code Playgroud)

椭圆形总是夹在边缘上.我怎样才能避免剪辑?是唯一的方法是插入矩形吗?

objective-c uikit drawrect ios uibezierpath

0
推荐指数
1
解决办法
350
查看次数

Objective-C:如何防止调用非默认初始值设定项?

我创建了一个不同的init方法,并希望它是指定的初始化程序而不是标准-init.如何防止客户端代码使用实例化类-init

例如

/* everyone must call this */
- (id)initWithInfo:(NSDictionary *)info {
  self = [super init];
  if (self) {
      _info = info;
  }

  return self;
}

/* Don't want anyone to be able to create this using init */
Run Code Online (Sandbox Code Playgroud)

objective-c initializer

-1
推荐指数
1
解决办法
295
查看次数

你能有一个包含捕获列表和参数列表的闭包吗?

在 Swift 中,如何创建一个包含捕获列表和参数的闭包?

我使用过以任何一种形式呈现的代码,但不知道如何创建具有参数和捕获列表的闭包。

例如

关闭参数列表:

myFunction {
    (x: Int, y: Int) -> Int in
    return x + y
}
Run Code Online (Sandbox Code Playgroud)

关闭捕获列表:

myFunction { [weak parent = self.parent] in print(parent!.title) }
Run Code Online (Sandbox Code Playgroud)

使用捕获列表的示例尝试:

class MyTest {
    var value:Int = 3

    func myFunction(f: (x:Int, y:Int) -> Int) {
        print(f(x: self.value, y: 5))
    }

    func testFunction() {
        myFunction {
            [weak self] (x, y) in   //<--- This won't work, how to specify weak self here?
            print(self.value)
            return self.value + y
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

parameters closures swift swift2

-1
推荐指数
1
解决办法
658
查看次数

使用String isEmpty检查空字符串

Swift编程语言提到使用isEmpty来检查空字符串.是否存在检查字符串与""不会产生与使用isEmpty相同的结果的情况?

换一种说法:

if str.isEmpty {
 XCTAssert(str == "", "This should be true as well")
}
Run Code Online (Sandbox Code Playgroud)

文档:

通过检查其布尔值isEmpty属性,确定String值是否为空:

if emptyString.isEmpty {
    print("Nothing to see here")
}
Run Code Online (Sandbox Code Playgroud)

string swift

-3
推荐指数
1
解决办法
289
查看次数