Tuesday 15 September 2015

objective c - Two line UILabel with word wrap and truncate also aligned at vertically top -


I have to take 2 line labels in the first line, I need line break mode NSLineBreakByWordWrapping and other lines on NSLineBreakByTruncatingMiddle as well as if text If fit in a line then it should be vertical top combine.

I am using iOS 6 and AutoLayout. I can align a line text at the top but the problem is that if the length of the text is above the first line then it fits in the middle of the first line and if the length of the text goes up from the other line It cuts in the middle and shows up on two lines.

My code:

  self.testLabel = [[UILBal Alok] init]; Self.testLabel.numberOfLines = 2; Self.testLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; Self.testLabel.preferredMaxLayoutWidth = 200; [Self.testLabel setContentHuggingPriority: Axis Required for UILayoutPriority: UILayoutConstraintAxisVertical]; [Self.testLabel setContentCompressionResistancePriority: Axis Required for UILayoutPriority: UILayoutConstraintAxisVertical]; [Self. Test Label Set Transactions Authorizing Missing In Consultants: No]; [Self.view addSubview: self.testLabel]; NSArray * constrs = [Visual format with NSLayoutConstraint constraints: @ "| -20 - [_ testLabel] -20- |" Options: 0 metric: zero views: NSDictionaryOfVariableBindings (_testLabel)]; [Self.view addConstraints: constrs]; [Self.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "V: | -20 - [_ testLabel]" option: 0 metric: zero views: NSDictionaryOfVariableBindings (_testLabel)]]; [Self.testLabel addConstraints: [NSLayoutConstraint constraintsWithVisualFormat: @ "V: [_ testLabel (42 @ 250)]" option: 0 metric: zero views: NSDictionaryOfVariableBindings (_testLabel)]];    

People there are so many blogs that need to configure your label according to your needs. Help.

The above link will definitely help you really

Cheers!

No comments:

Post a Comment