2016-03-17 2 views
0

У меня есть UILabel, который добавлен в UIView, и этот вид добавить в качестве подзадачи UIScrollView и масштабирование включено. Работать все отлично, но когда я увеличиваю масштаб, то UILabel и другие свойства тоже, и это выглядит довольно странно. Я также добавил следующий код для гибкого размера.UILabel Pixelated on Zoom in iOS App

userResizableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
userResizableView.autoresizesSubviews = YES; 

Above View является `UIView Type. И ниже код этикетки

UILabel * lbl_FormFieldName = [[UILabel alloc]initWithFrame:CGRectMake(1, 1, rect.size.width, 15)]; 
lbl_FormFieldName.attributedText = attrText; 

// lbl_FormFieldName.text = text; 
lbl_FormFieldName.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
lbl_FormFieldName.textColor = [UIColor blackColor]; 
lbl_FormFieldName.backgroundColor = [UIColor clearColor]; 
lbl_FormFieldName.font = customFont; 
lbl_FormFieldName.numberOfLines = 0; 
lbl_FormFieldName.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone 

lbl_FormFieldName.clipsToBounds = YES; 
lbl_FormFieldName.textAlignment = NSTextAlignmentCenter; 

Пожалуйста, дайте мне какие-либо предложения, как сделать хорошо. Ищете предложение. Thanks

ответ

0

Возможно, метка фрейма использует плавающие числа. Попробуйте это, чтобы заставить значение целых чисел для кадра:

[label setFrame:CGRectIntegral(label.frame)]; 
0
As per my requirement I have added pinch gesture on uilabel like this : 

1. Add this line before implementation. 
CG_INLINE CGRect CGRectScale(CGRect rect, CGFloat wScale, CGFloat hScale) 
{ 
    return CGRectMake(rect.origin.x * wScale, rect.origin.y * hScale, rect.size.width * wScale, rect.size.height * hScale); 
} 

2. Add gesture on label 

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(viewDidPinch:)]; 
pinch.delegate =self; 
[self addGestureRecognizer:pinch]; 

3. Add method in your file. Add scrollview bounds instead of self.bounds as I have different scenario in my case. 
- (void)viewDidPinch:(UIPinchGestureRecognizer*)sender 
{ 

    CGFloat scale = sender.scale; 

    CGRect scaleRect = CGRectScale(self.bounds, scale, scale); 

     if (scaleRect.size.width >= 5 && scaleRect.size.height >= 5) { 


      [self._label setAttributedText:[self getScaledStringFrom:self._label.attributedText withScale:scale]]; 

      [self._label setFrame:self.bounds]; 

    } 
    sender.scale=1.0; 

} 

4. Rewrite text with new scale 
- (NSMutableAttributedString*) getScaledStringFrom:(NSMutableAttributedString*)string withScale:(CGFloat)scale 
{ 
    [string beginEditing]; 
    [string enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, string.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { 
     if (value) { 
      UIFont *oldFont = (UIFont *)value; 
      UIFont *newFont = [oldFont fontWithSize:oldFont.pointSize * scale]; 
      [string removeAttribute:NSFontAttributeName range:range]; 
      [string addAttribute:NSFontAttributeName value:newFont range:range]; 
     } 
    }]; 
    [string endEditing]; 
    return string; 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^