Tôi có một văn bản (Câu chuyện của một cuốn sách). Tôi đang dùng UILabel để hiển thị nó. Nhưng nó không cho tôi xem. Tôi đang sử dụng mã sau:Văn bản không hiển thị trên UILabel khi văn bản quá lớn.
CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];;
[commentsTextLabel setNumberOfLines:0];
commentsTextLabel.textColor = [UIColor blackColor];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
[commentsTextLabel setFont:[UIFont fontWithName:@"ACaslonPro-Regular"size:17]];
labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
commentsTextLabel.frame=CGRectMake(20, 200, 280, labelsize.height);
commentsTextLabel.text = story;// more than 1000 lines
[self.view addSubview:commentsTextLabel];
Khi tôi gỡ lỗi mã, tôi đã tìm thấy nhãn. Chú thích sắp xuất hiện trong trường hợp của tôi 13145.Thanh toán không hiển thị. Nếu tôi giảm 15000 xuống 11000, thì văn bản sẽ hiển thị trên màn hình với .... cuối cùng.
ghi nhãn = [kích thước câu chuyệnWithFont: commentsTextLabel.font constrainedToSize: CGSizeMake (280, 15000) lineBreakMode: NSLineBreakByWordWrapping];
Hãy giúp tôi. Cảm ơn
tại sao bạn không sử dụng UITextView ....? – BhushanVU
Sẽ tốt hơn nếu sử dụng UITextView không thể chỉnh sửa? Nếu không, hãy thử đặt MAXFLOAT làm giới hạn chiều cao khi tính toán kích thước nhãn. – Jeepston
ở đây nhãn có nghĩa là loại biến nào? – Balu