user3661956
user3661956

Reputation: 49

Integer and string won't right pad.. Objective C

The code is below. What ends up happening is it's as if I used leftPadding instead of rightPadding and a string or long integer will run of the screen to the right. What I want is for the string is pad itself on the right and it's length extends to the left..

- (void)constructTimeStampLabel {
    CGFloat rightPadding = 250.f;
    CGFloat topPadding = -30.f;
    CGRect frame = CGRectMake(rightPadding,
                              topPadding,
                              floorf(CGRectGetWidth(__informationView.frame)),
                              CGRectGetHeight(__informationView.frame) - topPadding);
    _timeStampLabel = [[UILabel alloc] initWithFrame:frame];
    _timeStampLabel.text = [NSString stringWithFormat:@"Sent on %@", _feedItem.timeStamp];
    _timeStampLabel.textColor = [UIColor whiteColor];
    [_timeStampLabel setFont:[UIFont systemFontOfSize:12]];
    [__informationView addSubview:_timeStampLabel];
}

Upvotes: 1

Views: 71

Answers (1)

Rob
Rob

Reputation: 1034

try setting the alignment to the right.

_timeStampLabel.textAlignment = NSTextAlignmentRight;

Upvotes: 1

Related Questions