2017-03-23 24 views
1

我想用製作彎曲文本多行如何在目標c中使用多行製作彎曲文本

我曾用「CoreTextArcView.h」 &「CoreTextArcView.m」文件我發現了一個使彎曲文字,但是當我試圖如下像「你好\ nWolrd」多線曲線鍵入文本字符串

CGRect rect1 = CGRectMake(0, 120, 320, 120); 
UIFont * font1 = [UIFont fontWithName:@"Helvetica" size:26.0f]; 
UIColor * color1 = [UIColor whiteColor]; 
CoreTextArcView * cityLabel = [[[CoreTextArcView alloc] initWithFrame:rect1 
                  font:font1 
                  text:@"Hello\nWorld" 
                  radius:85 
                 arcSize:110 
                  color:color1] autorelease]; 
cityLabel.backgroundColor = [UIColor clearColor]; 

[self.view addSubview:cityLabel]; 

但是結果只顯示一行彎曲的文本,與我輸入的內容相同,如「Hello \ nWolrd」不影響多行效果。

我想是這樣的:

enter image description here

+0

你能告訴我們用多行顯示哪種輸出嗎?因爲曲線文本通常是單行且帶有圓角文本。 – CodeChanger

+0

我有添加輸出,這是我想@CodeChanger –

回答

0

直接與新線的文本是不是在上面定製類可能的,但你應該把一些邏輯和解決它像下面。

UIFont * font1 = [UIFont fontWithName:@"Helvetica" size:26.0f]; 
UIColor * color1 = [UIColor blackColor]; 

NSString *titleString = @"Hello\nWorld"; 
NSArray *strArray = [titleString componentsSeparatedByString:@"\n"]; 

int y = 120; 
for (NSString *strCurveText in strArray) { 
    CGRect rect1 = CGRectMake(0, y, 320, 70); 
    CoreTextArcView * cityLabel = [[CoreTextArcView alloc] initWithFrame:rect1 
                     font:font1 
                     text:strCurveText 
                     radius:35 
                    arcSize:90 
                     color:color1]; 
     cityLabel.backgroundColor = [UIColor clearColor]; 

     [self.view addSubview:cityLabel]; 

     y = y + (rect1.size.height/2); 
    } 

ArcSize半徑按你的文字大小。

希望這會幫助你。