使用此代码时,我的情况逐渐减弱
-(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
如果我像这样使用有任何问题..
或者请给我一个覆盖方法的确切方法谢谢......
答案 0 :(得分:0)
对于非UI自定义,最好是子类。将TextField类指定为CustomTextField,根据您的实现需要drawPlaceholderInRect
// CustomTextField.h
#import <UIKit/UIKit.h>
@interface CustomTextField : UITextField
@end
// CustomTextField.m
#import "CustomTextField.h"
@implementation CustomTextField
- (void)drawPlaceholderInRect:(CGRect)rect {
BOOL currentdevice=[[UIDevice currentDevice].model hasPrefix:@"iPhone"];
if(currentdevice){
NSDictionary *attrDictionary = @{
NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName : [UIFont fontWithName:@"OpenSans" size:15.0]
};
[[self placeholder] drawInRect:rect withAttributes:attrDictionary];
}
else{
NSDictionary *attrDictionary = @{
NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName : [UIFont fontWithName:@"OpenSans" size:20.0]
};
[[self placeholder] drawInRect:rect withAttributes:attrDictionary];
}
}
@end