Can we increase button height if the button label text is so long in iPhone? - iphone

I have put 4 buttons with 4 labels on the button as button title using interface builder. My button label shows the showroom name, email id...etc with font size 17 correct. But if Showroom name or email id get bigger then my button label shows information with small font size which looks odd and not according to apple HIG.
So can we increase button height programmatically to show button label title with consistent font size 17.

you can use 'sizeToFit' function to RESIZE button to it's content optimum display,
or
you can use 'sizeThatFits:CGSizeZero' to actually GET the optimum frame and do whatever you want with it.
OBS: this will only work if 'sizeThatFits' is bigger that original size, so i suggest you to set size to something like (1,1) before calling the functions above

Did you try with, something like this:
button.frame = CGRectMake(0,0,80,200)
to change the height of the button?

Related

How do you create a NSTouchBarItem that uses the remaining width in the Touch Bar?

I'm trying to create a NSButton that takes up the remaining space on the Touch Bar. My goal is to have a button similar to the "Search or enter website name" button in Safari.
I've looked at setting constraints with widthAnchor, but I'm completely lost at how to set it properly.
NSButton has an intrinsicContentSize that fits its content, and a default horizontal contentHuggingPriority of 750 (NSLayoutPriorityDefaultHigh), meaning it will strongly try to match that content width.
You can decrease that hugging priority (e.g. [button setContentHuggingPriority:1.0 forOrientation:NSLayoutConstraintOrientationHorizontal]) in order to make it more able to stretch away from that content, and in this case fill up the extra space in the touch bar.

Autolayout UIButton and UILabel font size according to specific type of the iPhone size[NOT PROGRAMMATICALLY]

I want to set different font size according to the IPhone size (4, 4.7 or 5.5 inch) Here is one of the solution
But I want to ask is there is any way to auto resize UIButton / UILabel font size through interface builder without code? For example, how it works with holding ratio width - height of the UIsmth size?
If there is no way to do it as I described - what is the best practice to set font sizes. Should I do it as separate file for each UI element or it s better to do it in the appropriate UI elem subclass?
To concrete the question - I'm writing an web app for iPhone portrait only
Yeah it's possible you can use sizeClass for it.
Select the viewController wich you want to change the sizeFont, then
HERE:
You select the sizeScreen you want (it will appears blue where you see "any/any" ) and then select the textField, go to the
Attributes inspector
and choose a new size clicking the plus button in the font section :
You will see something like this:
Select and change the size you want, It will work for you

iOS - Interface Builder: UIButton title disappears when setting image

I have made a project previously where I set a UIButton to have both text and also an image (in interface builder).
I have created another project and I want to achieve the same thing, but when I set the button to have an image, the title disappears (it's not getting hidden behind the image).
I can't seem to figure out why this is so if anyone could shed some light on this subject I'd appreciate it!
Thanks.
Change your button to custom type. put the image on then put the text in.
You will need to put your own background on it, but at that point you will be able to use the edge settings to position both the text and the image.
Every button that I have with image and text is set to custom and ultimately has its own bg image as well.
Oh, another thing I use. Is the cornerRadius. To give the view the rounded effect like the buttons have by default.
saveButton.layer.cornerRadius = roundingNumber.floatValue;
Additionally you should be able to use the borderWidth and borderColor in conjunction with cornerRadius to get a button that looks quite similar to the original button
saveButton.layer.borderRadius = 1.0f;
saveButton.layer.borderColor = [[UIColor blueColor] CGColor];
// These are not the exact values (or maybe they are) but you get the idea.
hope that helps.
Correction
After Spending a little time investigating, it appears that when you put an image in the button. the text is shoved off to the right.
Use the edge settings to bring it back over the image.
With the button selected, Look in "Attributes Inspector" > Button > Edge > (Dropdown "Title")
the equasion I have come up with is
[Edge inset for Title] Left = -(imageWidth * 2)
This should Left align your title with the image that you have put in.
Custom positioning will need to be done to make it look correct.
This can be done entirely in the Interface Builder and you can use RoundedRect button style
Here are some images demonstrating the change.
Here I set the Button type to "Custom" to remove the border and background.
Here I set the Top and Left in the Edge set for "Title" (Title is an option in the drop down)
EDIT
Newest Xcode has moved the size settings to a new location
Just put the image in the background field instead. This way the text will appear in front of the image.
It sounds like you are setting the image for the button but not the background image so reverse that.
I noticed that if the UIButton colour is set to default, adding an image makes it white and thus invisible. Changing the colour manually makes it visible again.

iPhone - Font used for Toolbar buttons

Could you tell me which font is used to display text on Toolbar buttons ?
I'm searching this to make a custom button.
Helvetica-Bold, 12 pt
Although you may be better off just creating the graphic (background) for the button and using the default title property of the button to set the relevant text.

Variable height UILabel

I'm working on a iPhone product page where some of the fields can be fairly long (product name etc.) I've created the page layout in IB, and use UILabels to show the text fields. For those long text labels I'd like the height of the label to scale and push the other labels further down. Is this possible using IB, or would I have to do everything in code? (Compute height and position of all the UILabels.)
I'm presently able to get the text in the labels to wrap and fill the available space, but I have to reserve space for this. When the label is only one line it leaves lots of unused space before the next label.
You will have to calculate the heights dynamically in code. I'm not sure what you're doing exactly, but you may want to start using a UITableView and return variable height cells. I wrote a blog post on how to do this at Cocoa Is My Girlfriend.
It did some searching for this same thing and as far as I can tell you have to manually resize and position the labels.
If you want to know how to dynamically resize a label, this is how I am doing it:
myLabel.frame = CGRectMake(227.0, 12.0, 22.0, 21.0);
I am happy to be wrong on this one, since I don't like having to do this either.