2

I am using UITableView.

UITableViewCell *tableViewCell = NULL;

tableViewCell = [historyTableView dequeueReusableCellWithIdentifier:@"Table cells"];

Now, how can i set opt alignment to tableViewCell.textlabel?

I tried setFrame too, but it didnt work.

Thanks Jithendra

IronManGill
  • 7,222
  • 2
  • 31
  • 52
Coder
  • 1,661
  • 4
  • 27
  • 50

3 Answers3

2

Use This link for verticale alignment text of UILable

otherwise alternative solution of your requirement is ,you can use UITextField, the subclass of UIControl, which inherits UIControl's the contentVerticalAlignment property.

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;

You can use this property to align the text on top. You can disable the user from editing the text by using the property userInteractionEnabled property.

also here see this labels-aligning-in-uitableviewcell many code

i hope this help you...

Community
  • 1
  • 1
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • @jithen see this link..http://blog.mick-walker.co.uk/uilabel-vertical-bottom-align – Paras Joshi Nov 26 '12 at 12:19
  • @jithen also use this class from this link mate https://iphonedevsdk.vanillaforums.com/forum/iphone-sdk-development/35532-uilabel-vertical-align-on-the-top.html – Paras Joshi Nov 26 '12 at 12:24
  • @jithen see my Updated answer mate with alternative solutions :) – Paras Joshi Nov 26 '12 at 12:43
  • I have gone through the code. So if i want to set the alignment to TOP, then i have to create instance for VerticallyAlignedLabel and add it to tableViewCell as subview. Please correct me if i am wrong. If this is right, then this is not what i wanted. My question is to set alignment for tableViewCell's default label text position. I can set top position creating new label using UILabel and adding it as subview to tableViewCell.. – Coder Nov 26 '12 at 13:09
  • yes mate i know so at last i post link for uitableviewcell's lable just go through that link also i give the idea that just add UItextField instead of UILable mate its very easy to use... what you say about it?? – Paras Joshi Nov 26 '12 at 13:16
  • No Mate.. even this is not helping me... Here they are taking third variable UILable , nowhere they used tableViewCell text label. But thanks for ur quick replies.. – Coder Nov 26 '12 at 13:27
  • mate i'll post code about this with testing my own code .. i use some code with text property of lable and then give some big property to it i'll post – Paras Joshi Nov 26 '12 at 13:30
-2

you can use

 tableViewCell.textLabel.textAlignment = UITextAlignmentRight; //you can use UITextAlignmentLeft, UITextAlignmentCenter aslo!! 

For Vertical alignment you need to use sizeToFit: method

Also Refer the bellow link

Vertically align text to top within a UILabel

Community
  • 1
  • 1
iDhaval
  • 7,824
  • 2
  • 21
  • 30
  • `UITextAlignmentRight` is depricated from IOS 6 release, instead use `NSTextAlignmentRight` – Radix Jul 21 '15 at 06:48
-4

You can set TOP align using your default tableViewCell.textlabel through this way

[cell.textLabel sizeToFit];

Enjoy Programming

Niru Mukund Shah
  • 4,637
  • 2
  • 20
  • 34
  • I can create new UITable instance and add it as subview to tabelviewcell. But my questions is how can i set TOP align using default tableViewCell.textlabel – Coder Nov 26 '12 at 12:07
  • try to improve your acccept rate otherwise noone will be ready to help you over stack overflow – Niru Mukund Shah Nov 26 '12 at 12:29
  • 1
    If i find it as good answer, definitely i will accept that reply. Thanks – Coder Nov 26 '12 at 12:54
  • 1
    I tried this code. But it is not working. Now do u want me to accept it? Sorry... – Coder Nov 26 '12 at 12:59