【发布时间】:2015-12-15 12:15:56
【问题描述】:
我在使用此代码时出现了这种减弱
-(void) drawPlaceholderInRect:(CGRect)rect {
// [[UIColor ] setFill];
BOOL currentdevice=[[UIDevice currentDevice].model hasPrefix:@"iPhone"];
if(currentdevice)
{
[[self placeholder] drawInRect:rect withAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:15] }];
}
else
{
[[self placeholder] drawInRect:rect withAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:20]}];
}
}
要停止我正在使用此代码的警告消息
@implementation UITextField (placeholder)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
// do your override
-(void) drawPlaceholderInRect:(CGRect)rect {
// [[UIColor ] setFill];
BOOL currentdevice=[[UIDevice currentDevice].model hasPrefix:@"iPhone"];
if(currentdevice)
{
[[self placeholder] drawInRect:rect withAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:15] }];
}
else
{
[[self placeholder] drawInRect:rect withAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:20]}];
}
}
#pragma clang diagnostic pop
如果我这样使用有什么问题吗..
或者请给我确切的方法来覆盖该方法谢谢....
【问题讨论】:
-
从技术上讲,它会起作用。但是,最好避免这种情况,因为从技术上讲,未定义将使用哪种实现的选择。
-
有没有办法以正确的方式做到这一点@Avi
-
子类化会更好。
-
你能简单解释一下如何做到这一点@Avi :)
标签: ios objective-c objective-c-category