UIsegment control Text size problem iphone - 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??

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)

#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. :-)

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.

Related

How to resize an NSImageView in an NSStackView?

I'm working on a project where I want the following in an NSTableViewCell:
Image
Text
Subtitle text
The NSTableView is in a window which the user can expand or contract. When the window expands and contracts, the text wraps as needed.
That much is working.
When it comes to the image view, I can't get the thing to resize at all. I don't understand how the text automatically wraps, but images don't automatically scale. I've been working on iOS so long that I might have missed something in how stack views differ between iOS and macOS, but I never had this problem in iOS.
I don't have much code because the text wraps properly without any code at all, so instead I posted a minimal project showing the problem on Github:
NSImageTableViewTest
Some things I tried:
I have to set the width/height of the image view, or the text won't wrap. It seems to me that the reason why is that if I keep the image view unbound, the table view starts at the width of the image.
I tried setting the leading and bottom constraints of the image view to no avail.
I tried setting the constraints of the NSStackView, but that doesn't help constrain the frame of the image view.
Question: do I have to change the frame of the image view in code? I did try that, to no avail.
At this point, I'm stumped and I'm sure the fix is something easy that I overlooked.
Thanks.
The image view doesn't shrink because the default Content Compression Resistance Priority is too high. Set the Content Compression Resistance Priority to (a bit lower than) "Low (250)".

Vertically aligning text within a UILabel and getting views below it to move up accordingly

I'm using the workaround described here to vertically align text in a multiline UILabel to the top. Unfortunately that solves only half of the problem because I also want to collapse the remaining space and move other labels below the label to move up and consume the space.
Is there anyone way to achieve this without having to resort to calculating the Frame's of the other views yourself and thus taking over the layouting?
Here's a screenshot of my problem. To make it easier I've colored the background of the relevant labels. The Blue label is supposed to move up and consume the unused space of the red label. The Red Label is configured for 3 Lines and Font-Autoshrink is off.
You must re-calculate your label frames and then rearrange your labels in the view.
Or you can try to use CoreText to make more complex layouts without the need to cope with these frames rearrangement. On GitHub there is a nice work BSD-licensed, called NSAttributedString+HTML: https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML which tries to port in the iOS the same methods already available in OSX. It is based on CoreText and with this class you can write your page as html and render it on screen without using UIWebView (and without its limitations). Based on your screenshot, it would be easy to achieve the wished result with simple html.

Why does my text look so bad in my ios App?

I have a uiscrollview that has a custom child view that contains text and images.
The text items are UILabels. I have attached an image representing the quality issue:
Do you guys think it might be worth a shot to draw the text, then convert to a uiimage and display that instead? Maybe it would scale better? Or perhaps there is a way to smooth the text?
There's no reason to expect that you're going to draw the text better than UILabel does. Your picture is very hard to make out, but here's what you want to look at:
Are you just adding a UILabel to the UIScrollView's contentView, or are you doing something else fancier. That "something else fancier" could easily be the problem.
Make sure you're drawing on pixel-aligned boundaries. The easiest way is to make sure the origin of your UILabel is integral (not a fraction). On a retina display, you can get away with half-points, but it's usually easier just to make everything integers.
I thinks it is the position issue. I bet you set the x or y value to float value like 12.3 or 12.5 .
What I have done now is I have created a uiimage version of my text and am showing that now instead of the uilabels, the quality is soo much better, you can really see the difference when you are looking at it scaled up on the ipad, it must just do a better job scaling images then text?
Before:
After:
The above images show how the text renders on the ipad with my app scaled up, before and after my change.

Embedded fonts in iOS: why are they not centered correctly on the y axis?

I've embedded a couple fonts in my iOS app and am finding that they're not centered correctly in labels and buttons, they're too high on the y axis, is there any solution for this? At first I thought it was just a cheap font file I was using but then I tried it (just to see) with an Adobe font and it still has the issue.
The (a?) solution a friend of mine pointed out is to use the contentEdgeInsets property of the button, I set it to:
myButton.contentEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 0);
To bump the text down 10 pixels and now the text is centered. Woot.
I've too struggled with this.
Depending on the situation, I'm using different solutions:
using insets when the element in question supports it
replacing the label in question with a view, which holds another label as its subview. I then move that new label within it's superview until it is centered. This works with titlebars and the like.
What I have not tried yet is subclassing UILabel (or even better: writing a category on it) to include a fix.
Maybe I'll write a bug report as well.
I'll keep you posted on that!
You should notice that UIControl classes have a property contentVerticalAlignment (as well as contentHorizontalAlignment).
The centering problem only occurs in UILabels. UITextViews are working properly. UIButton has a UILabel inside, and so, has the same problem.
To fix it, you can correct your font position with a tool like Font Creator. In my case we had to correct it with -200. This way you can use the UILabel as you normally do, no subclassing or extra categories.
Font Creator download link: http://www.high-logic.com/fontcreator.html

How to center a UIActivityIndicatorView along with text (UILabel)?

I've had this issue come up a couple times doing iPhone development now and have yet to find a good solution for it. What I'm looking for is this:
I want to show some text along with an icon and I want the overall display to be centered within its parent view. Specifically, in my current case, I'm looking to display a box that says "Reconnecting..." with a UIActivityIndicatorView to the left of the text.
Previously, I've just relied on the fact that I know exactly the dimensions of the text and activity indicator, so I can position things absolutely to appear centered. What I'm looking for is something more automatic.
Any ideas?
One of the UIKit additions to NSString will return the pixel size of the text if you give it the font that you're using on the UILabel. So then presumably the total size of the two things together in the layout you describe is:
the difference between label.frame.origin.x and activityIndicatorView.frame.origin.x; plus
the width of the text.
You can then either shuffle both the views appropriately or give them a common parent that's still a subview of the whole thing and shift that.
An activity indicator can be shown in a view just calling a single method.Please click here get SHKActivityIndicator class