简体   繁体   English

从Swift转换为Objective-C?

[英]Convert from swift to objective-c?

Guys can you please help me to convert this swift code to objective-c: 伙计们,您能帮我将这个快速代码转换为Objective-C吗?

import UIKit

@IBDesignable
class PushTheButton: UIButton {

    @IBInspectable var fillColor: UIColor = UIColor.greenColor()
    @IBInspectable var isAddButton: Bool = true

    override func drawRect(rect: CGRect) {

        let path = UIBezierPath(ovalInRect: rect)
        fillColor.setFill()
        path.fill()

    }

}

and where should I put the code? 我应该在哪里放置代码? is it in the header or implementation? 在标头或实现中? I would appreciate it if you could help me? 如果您能帮助我,我将不胜感激。

There will be two files on obj-c: header and implementation: obj-c上将有两个文件:标头和实现:

"PushTheButton.h" “ PushTheButton.h”

#import <UIKit/UIKit.h>

IB_DESIGNABLE
@interface PushTheButton : UIButton
@property (nonatomic) IBInspectable UIColor *fillColor;
@property (nonatomic) IBInspectable BOOL isAddButton;
@end

"PushTheButton.m" “ PushTheButton.m”

#import "FSView1.h"

@implementation PushTheButton

- (void)awakeFromNib {
    [super awakeFromNib];
    self.fillColor = [UIColor greenColor];
    self.isAddButton = YES;
}

- (void)drawRect:(CGRect)rect {
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
    [self.fillColor setFill];
    [path fill];
}

@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM