美文网首页iOS开发iOS DeveloperiOS学习笔记
iOS_黑(6)_修改系统级别文字

iOS_黑(6)_修改系统级别文字

作者: 丶纳凉 | 来源:发表于2017-06-12 16:35 被阅读84次

一丶事出原因

在使用webview加载链接的时候,需要定位服务,弹出:

@"..." Would Like To Use Your Current Location
Paste_Image.png

需求修改改成中文...
最终效果图:

Paste_Image.png

二丶解决方法

思路:利用Reveal 查看界面:

Paste_Image.png

是个Label;那就简单了:

#import "UILabel+HYDUI.h"

@implementation UILabel (HYDUI)


+ (void)load{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        Class selfClass = [self class];
        
        SEL oriSEL = @selector(setText:);
        Method oriMethod = class_getInstanceMethod(selfClass, oriSEL);
        
        SEL cusSEL = @selector(ZB_setText:);
        Method cusMethod = class_getInstanceMethod(selfClass, cusSEL);
        
        BOOL addSucc = class_addMethod(selfClass, oriSEL, method_getImplementation(cusMethod), method_getTypeEncoding(cusMethod));
        if (addSucc) {
            class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
        }else {
            method_exchangeImplementations(oriMethod, cusMethod);
        }
        
    });
    
}
- (void)ZB_setText:(NSString *)text{
    
    NSString *keyStr = @"Would Like To Use Your Current Location";
    NSString *key2Str = @"Don’t Allow";
    NSString *key3Str = @"OK";
    if ([text containsString:keyStr]) {
        NSString *urlStr = [[text componentsSeparatedByString:keyStr] firstObject];
        text = [urlStr stringByAppendingString:@"允许使用您当前的位置吗?"];
    }
   if ([text isEqualToString:key2Str]) {
        text = @"不允许";
    }
    if ([text isEqualToString:key3Str]) {
        text = @"好";
    }
    
    [self ZB_setText:text];
}
@end

三丶总结

解决办法:
1.保证系统是简体中文
2.info.plist增加

<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>zh_CN</string>
</array>

相关文章

网友评论

  • SpursGo:我艹 这尼玛不是所有设置文字是 ok的label都替换了???
    SpursGo:老哥稳
    丶纳凉:@SpursGo 对的,我觉得应该把“允许”改成“好”安全点:sweat_smile:
  • 421d4332fccb:就不告诉你:joy:
    丶纳凉:@猩猩只有一个 老星毛不要调皮

本文标题:iOS_黑(6)_修改系统级别文字

本文链接:https://www.haomeiwen.com/subject/uiwlqxtx.html