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

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

Related

dynamic button width in collection view cell

my collection view cell is full size..i have collection view cell and it contains button..i successfully display all button with it's title in collection view cell. but i am having one issue that some button title is too large..i want to change it's widht based on text...how to set button width based on text..i have vertical collection view
my array is
var arr = ["butto1 butto1 butto1","butto1 butto1butto1butto1","butto1","butto1 butto1butto1butto1"]
I have searched so many time but still i haven't point out
...any on help me..Thank you
You haven't given much information that would help in diagnosing your problem.
The button should automatically resize to fit the text unless you have set constraints that stop it from growing.
If you have set a left and a right constraint to equal a constant then it will not be able to grow.
As far as I can tell, you have two options.
Only set 3 out of 4 constraints. For example the following image has 3 constraints set which allow the button to grow downwards.
Set the right constraint to "Greater than or equal to" instead of "equal" in the interface builder. This will allow the button to grow to a maximum size which is specified by the constraints.
Also make sure to set your button to word wrap so that text continues on the next line.

swift - arrange buttons across many screens

I develop test app with swift ,
I need way to arrange first row in first screen to first row in second screen
to make all button across application look similar
my tries :
match X,Y value , width , height
Do you use Auto Layout ?
You can achieve that by
set vertical space between the top edge and your title
set horizontal alignment of title to be center of the view
set vertical space between title and the first item in the row
set leading margin of the first item in the first row
set horizontal alignment of all following items to be center of the first item

Space between the bars in the UISegmentedControl

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

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.

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.