iOS开发中遇到的问题整理09/4-2018

Q1:UITextView行数判断方式?

float rows = round((_textView.contentSize.height - _textView.textContainerInset.top - _textView.textContainerInset.bottom) / _textView.font.lineHeight);

Q2:Cell随UITextView高度变化而变化,UITableView刷新方式

[tableView beginUpdates];
 [tableView endUpdates];

Q3:UITextView即将换行时,当输入中文会带入拼音,解决方案

- (void)textViewDidChange:(UITextView *)textView {
    
    UITextRange *selectedRange = [textView markedTextRange];
    
    NSString * newText = [textView textInRange:selectedRange];//获取高亮部分
    
    if(newText.length>0){
        return;
    }
   
    //防止输入时在中文后输入英文过长直接中文和英文换行
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.alignment = NSTextAlignmentRight;
    NSDictionary *attributes = @{
                                 NSFontAttributeName:MN_RegularFontOfSize(16.0f),
                                 NSForegroundColorAttributeName:MN_HEXCOLOR(0x29292D),
                                 NSParagraphStyleAttributeName:paragraphStyle
                                 };
    textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
}

Q4:doule转字符串

 double d  = [number doubleValue];
NSString *dStr = [NSString stringWithFormat:@"%f", d];
NSDecimalNumber *dn =  [NSDecimalNumber decimalNumberWithString:dStr];
label.text  = [dn stringValue];

Q5:时间戳转转问题

默认是UTC 世界标准时间,需要转换为本地时间

NSDate* date = [NSDate dateWithTimeIntervalSince1970: message.receivedTime/1000.0];
NSTimeZone zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];

你可能感兴趣的:(iOS开发中遇到的问题整理09/4-2018)