가질 수 있는 방법이 여러 줄의 텍스트를 사용해야 하는 '또는' 에서 '대신' 위터스트비에프 유아벨 이와 같이 두 번째?
난 해결책을 찾아냈죠
그냥 한 다음 코드를 추가할 수 있다.
// Swift
textLabel.lineBreakMode = .ByWordWrapping // or NSLineBreakMode.ByWordWrapping
textLabel.numberOfLines = 0
// For Swift >= 3
textLabel.lineBreakMode = .byWordWrapping // notice the 'b' instead of 'B'
textLabel.numberOfLines = 0
// Objective-C
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
// C# (Xamarin.iOS)
textLabel.LineBreakMode = UILineBreakMode.WordWrap;
textLabel.Lines = 0;
(참고로 및 devs 지원할 의사가 있는지를 아래 iOS 6.0) 이전 오토메이티드 리스토어할.
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
측면: 이넘 값을 모두 '0' 굴하지 겁니다.
나는 최상의 솔루션을 http://support. (있어야 하는 문제가 해결되지 않은 답답한 것은 충족되었으며 있는 framework) 는 비슷한 vaychick& # 39 의.
Ib 또는 코드 인컨텍스트 줄 수를 0 으로 설정하면 됩니다
myLabel.numberOfLines = 0;
이렇게 하면 필요한 회선 표시하십시오 않지만, 그 가운데 맞춤입니다 레이블 그러하매 위치변경합니다 가로 (1 호선 및 3 호선 있도록 그들의 레이블은 정렬되고 수평 위치). 해결할 수 있는 추가:
CGRect currentFrame = myLabel.frame;
CGSize max = CGSizeMake(myLabel.frame.size.width, 500);
CGSize expected = [myString sizeWithFont:myLabel.font constrainedToSize:max lineBreakMode:myLabel.lineBreakMode];
currentFrame.size.height = expected.height;
myLabel.frame = currentFrame;
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
이 솔루션은 does& # 39 위, 내 경우에는 빗나갔다. # 39 m i& 하고, 다음과 같습니다.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...
CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Georgia-Bold" size:18.0] constrainedToSize:CGSizeMake(240.0, 480.0) lineBreakMode:UILineBreakModeWordWrap];
return size.height + 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
// ...
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Georgia-Bold" size:18.0];
}
// ...
UILabel *textLabel = [cell textLabel];
CGSize size = [text sizeWithFont:[UIFont fontWithName:@"Georgia-Bold" size:18.0]
constrainedToSize:CGSizeMake(240.0, 480.0)
lineBreakMode:UILineBreakModeWordWrap];
cell.textLabel.frame = CGRectMake(0, 0, size.width + 20, size.height + 20);
//...
}
var label = UILabel()
let stringValue = "A label\nwith\nmultiline text."
label.text = stringValue
label.numberOfLines = 0
label.lineBreakMode = .byTruncatingTail // or .byWrappingWord
label.minimumScaleFactor = 0.8 . // It is not required but nice to have a minimum scale factor to fit text into label frame
[enter 이미지 여기에 설명을] (https://i.stack.imgur.com/ej8F9.png)!
스토리 보르드 사용합니다. 제로 레이블에만 선택할 줄 수를 설정할 수 있습니다. [참조하거나 이] [2]
[2]: https://stackoverflow.com/questions/446405/adjust-uilabel-height-depending-on-the-text? rq = 1
이 사용해 보십시오.
lblName.numberOfLines = 0;
[lblName sizeToFit];
UILabel *helpLabel = [[UILabel alloc] init];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:label];
helpLabel.attributedText = attrString;
// helpLabel.text = label;
helpLabel.textAlignment = NSTextAlignmentCenter;
helpLabel.lineBreakMode = NSLineBreakByWordWrapping;
helpLabel.numberOfLines = 0;
그 이유는 일부 작동안함 가져다줄래요 iOS 6 의 이유는 확실하지 않다. 이 같은 텍스트 없이 함께 했다. 제안 사항을.
이 시도해야 합니다.
-(CGFloat)dynamicLblHeight:(UILabel *)lbl
{
CGFloat lblWidth = lbl.frame.size.width;
CGRect lblTextSize = [lbl.text boundingRectWithSize:CGSizeMake(lblWidth, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:lbl.font}
context:nil];
return lblTextSize.size.height;
}
이러한 것들이 나를 도와
이러한 특성을 유아벨 변경
label.numberOfLines = 0;
label.adjustsFontSizeToFitWidth = NO;
label.lineBreakMode = NSLineBreakByWordWrapping;
다른 말을 사용하는 동안 서로 다른 입력 문자열 \n 확증하노라 표시하십시오 흐름선.
예:
NSString *message = @"This \n is \n a demo \n message for \n stackoverflow" ;
extension UILabel {//Write this extension after close brackets of your class
func lblFunction() {
numberOfLines = 0
lineBreakMode = .byWordWrapping//If you want word wraping
//OR
lineBreakMode = .byCharWrapping//If you want character wraping
}
}
이제 이런 호츨 앨리어스가
myLbl.lblFunction()//Replace your label name
예:
Import UIKit
class MyClassName: UIViewController {//For example this is your class.
override func viewDidLoad() {
super.viewDidLoad()
myLbl.lblFunction()//Replace your label name
}
}//After close of your class write this extension.
extension UILabel {//Write this extension after close brackets of your class
func lblFunction() {
numberOfLines = 0
lineBreakMode = .byWordWrapping//If you want word wraping
//OR
lineBreakMode = .byCharWrapping//If you want character wraping
}
}
프로그래밍
yourLabel.numberOfLines = 0
yourLabel.lineBreakMode = .byWordWrapping//If you want word wraping
//OR
yourLabel.lineBreakMode = .byCharWrapping//If you want character wraping
스토리 보드 통해
여러 줄로 표시하십시오 설정되었습니다 0 (영), 이 두 개 이상의 줄을 너회의 레이블에만 표시됩니다.
N 개의 줄을 표시할 경우, 집합 n.
화면 아래.
설정할 경우 최소 글꼴 글꼴 크기 옵션을 선택하고 최소 크기의 레이블에만 오토시링크 클릭합니다.
화면 아래 참조
여기에 세트 최소 글꼴 크기
예: 9 (이 이미지)
당시 레이블에만 경우 더 많은 텍스트 사용자 레이블에만 upto 9 축소 것임