As per subject, my code as below
- (void)viewDidLoad
{
// Add Scroll View
CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:fullScreenRect];
self.view = scrollView;
// Configure Scroll View
scrollView.contentSize = CGSizeMake(320, 500);
// Shop Detail
CGRect shopDetailFrame = CGRectMake(20, 5, 300, 80);
UITextView *shopDetail = [[[UILabel alloc] initWithFrame:shopDetailFrame] autorelease];
shopDetail.backgroundColor = [UIColor whiteColor];
shopDetail.font = [UIFont boldSystemFontOfSize:15];
NSString *shopName = @"Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road";
shopDetail.text = [[shopName stringByAppendingString:@"\n"] stringByAppendingString:shopName];
[scrollView addSubview:shopDetail];
[super viewDidLoad];
}
Suppose the output is:
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road
But I got:
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road...
The \n not work on UITextView, anyone know how to make line break on UITextView?
Thanks
It’s this line:
You’re creating a UILabel instead of a UITextView.
You can still use a UILabel, but by default it will only show a single line. To make a UILabel show more lines, you need to set the
numberOfLinesproperty to either0(for no limit) or the number of lines you actually need.