Добавить разрыв строки "\ n" в UITextView, но не работает - PullRequest
0 голосов
/ 09 декабря 2011

По предмету мой код как ниже

- (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];
}

Предположим, что вывод:

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

Но я получил:

Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road...

\n не работает в UITextView, кто-нибудь знает, как сделать разрыв строки в UITextView?

Спасибо

Ответы [ 2 ]

2 голосов
/ 09 декабря 2011

Вот эта строка:

UITextView *shopDetail = [[[UILabel alloc] initWithFrame:shopDetailFrame] autorelease];

Вы создаете UILabel вместо UITextView.

Вы все еще можете использовать UILabel, но по умолчанию он будет показывать только одну строку. Чтобы UILabel показывал больше строк, вам нужно установить для свойства numberOfLines либо 0 (без ограничений), либо количество строк, которое вам действительно нужно.

0 голосов
/ 29 октября 2015

Если вы используете \n программно, это работает.

var txt_Other_Proj = String()
txt_Other_Proj = "Other Jessit Apps and Projects"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Hurkle: A FIND ME game"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "A free game."
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Candida Cookbook"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Living with Candida Albicans"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Visit www.Jessit.com"

main_Info.text = txt_Other_Proj
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...