我怎麼以下子類代碼轉換成快捷3.1.1 我一直在努力,我自己轉換,但我得到了太多的錯誤從Objective-C的轉換的UILabel子類斯威夫特
#import <UIKit/UIKit.h>
@interface myTextLabels : UILabel
@property (nonatomic) IBInspectable NSString *overrideFontName;
@property (nonatomic) IBInspectable CGFloat iphoneFontSize;
@property (nonatomic) IBInspectable CGFloat ipadFontSize;
@end
#import "myTextLabels.h"
@implementation myTextLabels
- (void)setOverrideFontName:(NSString *)overrideFontName
{
if (![_overrideFontName isEqualToString:overrideFontName])
{
_overrideFontName = overrideFontName;
self.font = self.font;
}
}
- (void)setFont:(UIFont *)font
{
NSString *overrideFontName = self.overrideFontName;
if (overrideFontName != nil)
{
font = [UIFont fontWithName:overrideFontName size:font.pointSize];
}
[super setFont:font];
}
@end
嘗試過各種東西,但錯誤太多 這裏我嘗試
import Foundation
import UIKit
class myTextLabel:UILabel{
@IBInspectable var overrideFontName: String = ""
@IBInspectable var iphoneFontSize: CGFloat = 0.0
@IBInspectable var ipadFontSize: CGFloat = 0.0
func setOverrideFontName(_ overrideFontName: String) {
if !(self.overrideFontName == overrideFontName) {
self.overrideFontName = overrideFontName
font = font
}
}
func setFont(_ font: NSFont!) {
let overrideFontName: String = self.overrideFontName
if overrideFontName != nil {
font = UIFont(name: overrideFontName, size: font.pointSize)
}
super.font = font
}
}
瓦你有錯誤嗎? – Fogmeister
使用Objective-C選擇器'setOverrideFontName'的方法'setOverrideFontName'與具有相同Objective-C選擇器的'overrideFontName'的setter衝突 – Superllanboy