2011-12-09 7 views
0

を働く、" n" はUITextViewに追加改行ではなく、対象を1として

- (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

それはこの行です:

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

あなたが代わりにUITextViewのUILabelを作成しています。

UILabelは引き続き使用できますが、デフォルトでは1行しか表示されません。 UILabelにもっと多くの行を表示させるためには、プロパティを0(制限なし)または実際に必要な行数に設定する必要があります。

+0

+1ありがとうございます –

0

\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 
関連する問題