iOS UITextView将字符放到下一行

时间:2015-01-20 23:18:07

标签: ios uilabel uitextview

cut off where it says Coordinat

在这张图片中,UITextView说“坐标几何”,“e”被放到下一行。那里没有行间距。我也尝试过UILabel(我切换到UITextView尝试修复问题,但没有区别)。

这是我的UITextView子类的代码      - (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text circular:(BOOL)isCircular {         self = [super initWithFrame:frame];

    if (self) {
        self.backgroundColor = [UIColor lightGrayColor];//[UIColor clearColor];
        self.alpha = 0.5;
        self.textColor = [Styles mainTextColour];
        [self setFont:[Styles heading2Font]];
        [self setTextAlignment:NSTextAlignmentCenter];
        self.text = text;
        self.editable = NO;

        self.contentInset = UIEdgeInsetsMake(-8, 0, -8, 0);
        [self resizeFontToFix];
    }

    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    NSAssert(NO, @"Don't use BubbleText -initWithFrame:, use -initWithFrame: andText: instead");
    return nil;
}

- (void)resizeFontToFix {
    //Resize to fix
    CGFloat fontSize = self.font.pointSize;
    CGFloat minSize = 6.0 * [Styles sizeModifier];
    while (fontSize > minSize &&  [self sizeThatFits:(CGSizeMake(self.frame.size.width, FLT_MAX))].height >= self.frame.size.height) {
        fontSize -= 1.0;
        self.font = [self.font fontWithSize:fontSize];
    }

//this below resizes to fit and centres the resulting view
//    [self resizeFrameAndCentre];
}

- (void)resizeFrameAndCentre {
    CGRect originalFrame = self.frame;
    [self sizeToFit];

    CGPoint centre = self.center;
    centre.x = originalFrame.origin.x + (originalFrame.size.width / 2);
    centre.y = originalFrame.origin.y + (originalFrame.size.height / 2);
    self.center = centre;
} 

0 个答案:

没有答案