iOS 常见适配问题

1、iOS 6 cell自定义分割线,在xib中会造成适配问题(不显示)

//适配iOS 6   
 [(UIView *)[self viewWithTag:lineTag] removeFromSuperview];
    UIColor *LCN = [[ThemeManager sharedThemeManager] colorWithColorKey:COLOR_LCN];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(50, 59.5, 270, 0.5)];
    line.backgroundColor = LCN;
    [self addSubview:line];

2、iOS 给UITextView加上UILabel作为提示语时,起始位置会不对应。

3、iOS系统弹窗适配

//调用弹窗
[self creatAlertForCompleteMessage:@"评价完成,确认提交吗?" tag:1];

- (void)creatAlertForCompleteMessage:message tag:(int)tag{
    if (tag == 1) {
        if ([ResourceUtil getSystemVersion] >= 8.0) {
            MSGSAlertController *alert = [MSGSAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            }];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                [self startLoading];
                dispatch_async([[GCDUtil sharedGCDUtil] defaultRequestQueue], ^{
                    if (!EMPTY_STRING(commentsTextView.text)) {
                        content = commentsTextView.text;
                    }
                    content = [[EmojiUtil sharedEmojiUtil] emojiEnglishFormChinese:content];
                    [self.playService submitApprasialInfoWithPlayId:self.playInfo.playid OrderId:self.playInfo.playOrder.playOrderId star:stars  desc:desc content:content images:selectedImages Success:^() {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self stopLoading];
                            if ([self.isAppraisalSucessDelegate respondsToSelector:@selector(isAppraisalSucess:)]) {
                                [self.isAppraisalSucessDelegate isAppraisalSucess:YES];
                            }
                            [self.navigationController popViewControllerAnimated:YES];
                            [self showToast:@"评价提交成功"];
                        });
                    } failure:^(NSError *error) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self showError:error];
                            [self stopLoading];
                        });
                    }];
                });
            }];
            [alert addAction:cancelAction];
            [alert addAction:okAction];
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
        }else{
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            [alert show];
            [alert setTag:tag];
            [[MSGSAdapterUtil sharedAdapterUtil] setAlertView:alert];
        }
    }
}
//适配iOS 8以下系统
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 1) {
        if (buttonIndex == 1) {
            [self startLoading];
            dispatch_async([[GCDUtil sharedGCDUtil] defaultRequestQueue], ^{
                if (!EMPTY_STRING(commentsTextView.text)) {
                    content = commentsTextView.text;
                }
                content = [[EmojiUtil sharedEmojiUtil] emojiEnglishFormChinese:content];
                [self.playService submitApprasialInfoWithPlayId:self.playInfo.playid OrderId:self.playInfo.playOrder.playOrderId star:stars  desc:desc content:content images:selectedImages Success:^() {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self stopLoading];
                        if ([self.isAppraisalSucessDelegate respondsToSelector:@selector(isAppraisalSucess:)]) {
                            [self.isAppraisalSucessDelegate isAppraisalSucess:YES];
                        }
                        [self.navigationController popViewControllerAnimated:YES];
                        [self showToast:@"评价提交成功"];
                    });
                } failure:^(NSError *error) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self showError:error];
                        [self stopLoading];
                    });
                }];
            });
        }
    }
}



4.UITextView输入字数限制,pad和iphone会有不同


#pragma mark - textView Delegate     for pad
- (void)textViewDidChange:(UITextView *)textView{
    if(textView.text.length == 0) {
        _commentInfoRightLabel.alpha = 1;
        _commentInfoRightLabel.hidden = NO;
    }
    else {
        _commentInfoRightLabel.alpha = 0;
        _commentInfoRightLabel.hidden = YES;
    }
    if(_commentInfoRightTextView == textView){
        
        float contentSizeHeight = textView.contentSize.height;
        if (contentSizeHeight < 54) {
            contentSizeHeight = 54;
        }
        frameSizeHeight = textView.frame.size.height;
        float height = contentSizeHeight - frameSizeHeight;

        textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, contentSizeHeight);
        _commentInfoView.frame = CGRectMake(_commentInfoView.frame.origin.x, _commentInfoView.frame.origin.y, _commentInfoView.frame.size.width, textView.frame.size.height);
        [self updateContentViewFrame:height];
    }
    if ([textView.text isEqualToString:@"\n"]){
        return ;
    }
    NSString * toBeString = textView.text;
    if (_commentInfoRightTextView == textView) {
        if ([MSGSUtility convertToDouble:toBeString]>100) {
            textView.text = [MSGSUtility subStringFromStr:toBeString withCharacterLenght:100];
            [self showToast:@"输入字数不能超过50字哦!"];
            return ;
        }
    }
    return ;
}
#pragma mark - textView Delegate  for  iphone
-(BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    if ([text isEqualToString:@"\n"]){
        return NO;
    }
    NSString * toBeString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    if (_commentInfoRightTextView == textView) {
        if ([MSGSUtility convertToDouble:toBeString]>100) {
            textView.text = [MSGSUtility subStringFromStr:toBeString withCharacterLenght:100];
            [self showToast:@"输入字数不能超过50字哦!"];
            return NO;
        }
    }
    return YES;
}


5.UILabel自适应文本

NSString *name = user.nickName;
        CGSize size = CGSizeMake(110,22);
        CGFloat originX;
        nickName.numberOfLines = 1;
        if([ResourceUtil getSystemVersion] >= 7.0){
            CGRect rect = [name boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName: nickName.font} context:nil];
            originX = 160 - (rect.size.width + 9 + 16)/2;   //昵称和等级居中显示
            nickName.frame = CGRectMake(originX, nickName.frame.origin.y, rect.size.width, rect.size.height);

        }else{
            CGSize labelsize = [name sizeWithFont:nickName.font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
            originX = 160 - (labelsize.width + 9 + 16)/2;   //昵称和等级居中显示
            nickName.frame = CGRectMake(originX, nickName.frame.origin.y, labelsize.width, labelsize.height);
        }
        vipButton.frame = CGRectMake(nickName.frame.origin.x + nickName.frame.size.width + 9, nickName.frame.origin.y + 2, 22, 15);
        [nickName setText:GET_STRING(name)];




转载于:https://my.oschina.net/u/1782374/blog/487732

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值