Jean-Luc Godard
Jean-Luc Godard

Reputation: 1883

UIsegment control Text size problem iphone

I have made a segment control.

In that my title is too much long .. so it is not shown properly..

Can Anyone tell me how to fix this problem??

Upvotes: 0

Views: 4511

Answers (3)

Kobski
Kobski

Reputation: 1636

The solution is to use the fact that a segmented control can also be built from an array of UIImages.

You can convert from text to UIImage this way:
How do I use the NSString draw functionality to create a UIImage from text

It should be fairly easy to change the fontsize.

Upvotes: 1

Parth Bhatt
Parth Bhatt

Reputation: 19469

@rathodrc:

It is not possible to change the font size for the segmented control but there is a work around for this, if you have fixed segment titles.

For Example:

Say if title for each segment is fixed that segmentedControl with 3 segments have titles(say SegA,SegB and SegC)

Then you can create images for each segment of segmentedcontrol with Segment title on it.

There you can keep larger or smaller fonts as per your requirement while creating images with text written on the image itself and then simply set images for each of the segments in the XIB.

Keep in mind, the image size should be exactly same as width and height of segment.

NOTE:

If you give the segment titles dynamically and it keeps on changes dynamically in your app then it is not possible.

Hope this helps you. :-)

Upvotes: 1

Jilouc
Jilouc

Reputation: 12714

I think there is no documented way to change the font.
But you can change the width of each segment using

[yourSegmentedControl setWidth:somethingLargeEnough forSegmentAtIndex:segmentIndex];

(though it may not be sufficient in your case)

Upvotes: 5

Related Questions