美文网首页
iOS获取系统语言,个人界面封装,语言国际化

iOS获取系统语言,个人界面封装,语言国际化

作者: f2efa87f6528 | 来源:发表于2016-09-30 16:37 被阅读106次
    iOS获取系统语言

    #######在编程中我们可能需要获取用户设置的手机语言,直接上代码
    NSString *identifier = [[NSLocale currentLocale] localeIdentifier]; // 比如中文是en_Zh
    NSString *displayName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];

    • 我们可以根据identifier和displayName来判断用户设置的语言为哪一种

    个人界面封装

    写的时候是纯代码,话说纯代码真的很难布局哎~在这里我使用的是Masonry,废话不多说,直接上代码吧!
    前面是tableView的展示,在这里自定义了cell分割线的一种方式
    数据源方法

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return _nameArr.count;
        
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        MYUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (!cell) {
            cell = [[MYUITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = _nameArr[indexPath.row];
        return cell;
    }
    

    这里大家看一下我的数据源,这个数据源这样写是为了做语言国际化,等下会讲

        NSArray *nameArr = @[_YUN(@"YUN_ME_my message"),_YUN(@"YUN_ME_browsing history" ),_YUN(@"YUN_ME_my camp"),_YUN(@"YUN_ME_my Interest"),_YUN(@"YUN_ME_about us")];
        _nameArr = [NSMutableArray arrayWithArray:nameArr];
    

    接下来我们自定义tableView的头部视图和他的cell
    这是头部视图的属性

    @property (nonatomic, strong)UILabel * postNumberLabel;            //帖子数量Label
    @property (nonatomic, strong)UILabel * postLabel;                  //帖子label
    @property (nonatomic, strong)UIButton * postBtn;                   //帖子button
    
    @property (nonatomic, strong)UILabel * concernNumberLabel;         //关注数量Label
    @property (nonatomic, strong)UILabel * concernLabel;               //关注label
    @property (nonatomic, strong)UIButton * concernBtn;                //关注button
    
    @property (nonatomic, strong)UILabel * fansNumberLabel;            //粉丝数量Label
    @property (nonatomic, strong)UILabel * fansLabel;                  //粉丝Label
    @property (nonatomic, strong)UIButton * fansBtn;                   //粉丝button
    
    @property (nonatomic, strong)UIImageView * backGroundImageView;    //头部背景
    
    @property (nonatomic, strong)UIImageView * iconImageView;          //头像
    @property (nonatomic, strong)UILabel * nameLabel;                  //姓名
    
    @property (nonatomic, assign)CGRect MYFrame;
    
    @property (nonatomic, weak)id <HeadViewDelegate>delegate;
    

    头部视图的代理.用来传递头部视图的按钮点击事件

    @protocol HeadViewDelegate <NSObject>
    
    - (void)concernBtnClick:(UIButton *)concernBtn;
    - (void)postBtnClick:(UIButton *)postBtn;
    - (void)fansBtnClick:(UIButton *)fansBtn;
    
    @end
    

    接下来就是头部视图属性的懒加载和布局,代码比较多哦

    相关文章

      网友评论

          本文标题:iOS获取系统语言,个人界面封装,语言国际化

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