小编ees*_*osu的帖子

如何使用Swift更改iOS中UIButton的状态?

我有六个按钮的Objective-C工作代码,但我似乎没有找到如何使用Swift更改按钮的状态.那么如何让以下代码在Swift中运行?

[self.button2 setBackgroundImage:[UIImage imageNamed:@"button2_selected.png"] forState: UIControlStateSelected];
button1.selected = NO;
button2.selected = !button2.selected;
button3.selected = NO;
button4.selected = NO;
button5.selected = NO;
button6.selected = NO;
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uibutton ios swift

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

在swift的collectionView中心获取cell的indexPath?

我试过这个通过使用uicollectionview的扩展来获取集合视图中心的单元格的索引,但我总是得到nil而不是索引.我怎样才能解决这个问题?

extension UICollectionView {
    var centerPoint : CGPoint {
        get {
            return CGPoint(x: self.center.x + self.contentOffset.x, y: self.center.y + self.contentOffset.y);
        }
    }

    var centerCellIndexPath: NSIndexPath? {
        if let centerIndexPath: NSIndexPath  = self.indexPathForItemAtPoint(self.centerPoint) {
            return centerIndexPath
        }

        return nil
    }
}
Run Code Online (Sandbox Code Playgroud)

那么:在随机方法的UIViewController中我有这个:

if let centerCellIndexPath: NSIndexPath  = collectionTemp!.centerCellIndexPath {
    print(centerCellIndexPath)
} else {
    println("nil")
}
Run Code Online (Sandbox Code Playgroud)

索引路径总是为零,我不明白为什么,因为单元格按顺序显示,除此之外一切都很好.

nsindexpath ios uicollectionview uicollectionviewcell swift

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

如何使用swift访问MacOSX Cocoa应用程序中的辅助功能设置?

我很困惑.通常在iOS应用程序中,我将使用url方案访问设置.现在我发现使用Objective-C在MacOSX上你可以这样做:

    NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
    BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
Run Code Online (Sandbox Code Playgroud)

我试图将其转换为Swift但没有得到有效的结果.有谁知道如何转换这个或一个有效的方法来请求在Swift中的辅助访问?

permissions macos cocoa objective-c swift

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

如何使用realm swift检索另一个对象列表中的对象?

我有一些看起来像这样的Realm类:

class Friends: Object {
    dynamic var name = true
    dynamic var role = true
    dynamic var type = true
    dynamic var owner: Profile?
}

class Profile: Object {
    dynamic var uuid = NSUUID().UUIDString
    dynamic var name = ""
    dynamic var date = NSDate(timeIntervalSinceNow: 1)
    dynamic var section = 0
    dynamic var code = ""
    dynamic var gender = 0
    dynamic var type = ""
    let friends = List<Friends>()

    override static func primaryKey() -> String? {
       return "uuid"
    }
} …
Run Code Online (Sandbox Code Playgroud)

object realm ios swift realm-list

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

如何快速使用贝塞尔曲线路径创建大小不同的图饼?

我想制作一个具有8个相等切片的漂亮图形饼图,可以根据一个Int或类似的东西进行单独缩放或调整大小。如下所示,只是将所有切片均等地切割:

在此处输入图片说明

我曾在Objective-C中尝试过此方法,但它仅占一小部分:

  -(CAShapeLayer *)createPieSlice {
    CAShapeLayer *slice = [CAShapeLayer layer];
    slice.fillColor = [UIColor redColor].CGColor;
    slice.strokeColor = [UIColor blackColor].CGColor;
    slice.lineWidth = 3.0;

    CGFloat angle = DEG2RAD(-60.0);
    CGPoint center = CGPointMake(100.0, 100.0);
    CGFloat radius = 100.0;

    UIBezierPath *piePath = [UIBezierPath bezierPath];
    [piePath moveToPoint:center];

    [piePath addLineToPoint:CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle))];

    [piePath addArcWithCenter:center radius:radius startAngle:angle endAngle:DEG2RAD(60.0) clockwise:YES];

    //  [piePath addLineToPoint:center];
    [piePath closePath]; // this will automatically add a straight line to the center
    slice.path = piePath.CGPath;

    return slice;
    } …
Run Code Online (Sandbox Code Playgroud)

graphic ios uibezierpath quartz-core swift

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