Space between the bars in the UISegmentedControl - iphone

How do I increase the space between the bars in a UISegmentedControl? Instead of creating a separate button. I want to split the segment control bars.

Set width using the following method,
[segment setWidth: forSegmentAtIndex:];
This will allow you to increase the width of the individual segments.
Update:
If you want to split the individual segments, you might have to put a custom image as the dividerImage to make it look like it is separate. You need to use the below method for setting dividerImage.
- (void)setDividerImage:(UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics

Related

How can i resize UIView for an amount of UILabels and resize UILabels to fit text?

I have an UIView that it should contains UILabels, and these UILabels are not fixed if an UILabel is nil, i don't display it, and if is not i must resize the UILabel to fit text (they can be 2 ligne) and put it under another UILabel, and after i must resize the UIView container for the amount of this UILabels. this the Screen Shot that i want to do programmatically:
UILabels can fit large amounts of text by automatically making the font smaller (see the minimum font size value in the Interface Builder). Instead of labels, I would use UITextViews. They fit large amounts of text by allowing the user to scroll. To make them hidden, use change the hidden selector attribute of the UITextViews. Because the UITextViews will never change in size, you can easily calculate how much to decrease the height of the UIView container by per UITextView. Hope this helps!
I think you have to calculate the height of the labels (more specifically, the addition from the original height) one by one. Of course you should be able to do this systematically by having all the labels in an array.
You can use [NSString sizeWithFont:] methods (there are several with similar names) to calculate the height.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html
If you want to keep the same font size then you can calculate the frame size for the label at run time depending upon the length of the text..
See here
You need to used following two properties of label-
lineBreakMode
numberOfLine
when you use both of these properties then you will achieve what you want.

Represent Number Line in iphone app

I am looking to display number line in my application
How this can be done? I also want to control number like programatically
you can use views with different sizes and background colours. Use #define -s for the fixed sizes.
You should have 3 functions:
one that draws the horizontal red/blue rects
-(UIView *) drawHorizontal:(CGRect)frame withColor:(UIColor)theColor;
one that draws vertical spacers and labels underneath. Iterate for whole line width.
-(UIView *) drawVertical:(CGPoint)centerPosition withLabel:(int)number;
Your number line should be stored as an NSArray of NSDictionaries containing the position (index) and length of the horizontal red/blue lines.
Hope this helps.
There's no easy standard component to do this. You will need to subclass UIView and override drawRect. Then you can use Core Graphics to draw the number line.

How to add horizontal bar in table row whose width depends on the value passed

I am implementing vote application in which i need to show horizontal bar in table row whose width is depended on particular value. This horizontal bar will act as a indicator to show percentage of vote.
One solution could be like this.....
Use two UILabels..... with different color..... combined length of this label would be 100px and we will vary individual's length based on the percentage......
Thanks,
You can use progress bar in the 'cell. backgroundView'.
or you can have imageView and overriding its draw rect method to draw the percentage of votes

Multiple UILabel(s) repositioning according to wordwrap

I have this interface with multiple UILabels.
On view loading i populate white labelled values with some data from a db.
The problem is, some of that fields are potentially too long for the interface, so i'd like to compute the total height of one label once the text is word wrapped and reposition the 2 labels below (shifting the Y coordinate) accordingly to the previous label's height.
All of this should go inside a UIScrollView to let the user scroll those labels vertically.
Any chance i can do this easily with some control i still don't know, or do i have to do it manually?
Thanks
You'll need to use the NSString UIKit Additions to compute the height you need to set on your UILabel, and then adjust the other controls appropriately.
Specifically, I think you want to use sizeWithFont:forWidth:lineBreakMode: to get the rect for your UILabel.
Alternatively, you could use a UIWebView and display the information as HTML. I don't know if it's necessarily less work, but you'll get a layout that automatically adjusts to the size of its contents.

UILabel automatic size and position

I want to draw a text with different colors and the only way that I've found for do it is to split every piece of string-color in differents UILabels, so currently now I have four UILabels one after another, lets say, label1, label2, label3 and label4.
The problem with that is with the size and the position of every labels, I've not found an automatic way for do it.
The only way is:
Set the text inside all the labels
Ask for the width of all the labels with this new text
Resize all the labels with this new width
Move label2 to label1.x + label1.width, and so on
This is really the only way in iPhone for do that?
I came from Android and there is a "wrap_content" property for every view and "relative_layouts" where you can define something like.. put label2 rightOf label1. So I'm looking of something simple and automatic like that, but in iPhone.
Thanks!
Depending on your application, you might want to consider a single UIWebView instead. Then you can style the content of it with HTML and CSS.