hi i want to resize my button width by text length when adding title right insets
i tried set Constant 100 and Priority 1000 and it work perfect
but when i add image and right insets,
button title show like this
"apple...omputer"
and i tried this
button.invalidateIntrinsicContentSize()
and
button.sizeToFit()
still not work and still show "..." in my button text
and i tried to add width after set button title in viewdidload, but still not working
button.frame = CGRect(button.frame.origin.x, button.frame.origin.y, button.frame.width+50, button.frame.height)
Storyboard buttons
Resizing button because text became larger
Please look at screenshots above. You need to set your insets and set right constraints. Autolayout does it for you.
I have a problem regarding the UIButton title in iOS5. They are clipped and show like in this photo. I don't want them to be clipped, i want to show the full title.
In iOS6, they work perfectly.
Please tell me how can i resolve this?
you simply need to increase the width of your UIButton to show full Title, i have posted sample snippet for better idea, try it. You just need to increase the width of button.
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setFrame:CGRectMake(20, 200, 150, 25)];
[btn1 setTitle:#"This is Long Title" forState:UIControlStateNormal];
[self.view addSubview:btn1];
Guys i have found the solution.
It was pretty simple, you just need to set the button font size in the interface builder to a larger or the same font size than that of the UIapperance font proxy.
I think AutoLayout may be the culprit for this. Check to see if your constraints aren't forcing the label to shrink.
I assume that you are setting your custom font from the code but you are setting the text for the buttons from the IB. So my simple explanation is that as #MichaelScaria said, your custom font is larger. The text is clipping because the size of the label inside the button is adjusted for the current font and size. Since you are changing the font and size after the text is set you need to re-set the title of the button or call 'sizeToFit' on that button.
For those of you here due to ellipsis and use of UIBarButtonItem know that there is a possibleTitles property on UIBarButtonItem with docs that read:
Use this property to provide a hint to the system on how to correctly size the bar button item to be wide enough to accommodate your widest title. Set the value of this property to an NSSet object containing all the titles you intend as possible titles for the bar button item. Use the actual text strings you intend to display.
This property applies to bar button items placed on navigation bars or toolbars.
I have set the title for navigation item on top of the screen. But the title text exceeded from the screen width. So I need scrolling title on the top of the screen. How to do this with MonoTouch? Is it possible?
You will most likely have to set a custom view for the text in the UINavigationItem's toolbar.
I have done similar with UIBarButtonItems, basically I created a UILabel with a width and centered text and set it as the custom view for it.
Take a look at this example, it's in Objective-C but you get the idea.
I have a tabBar, and I want to customise the items in the tab bar. I want to prevent the display of the title (easily achieved by setting the title to nil), and reset the icon position to be in the central vertical position. Does anyone have any idea of how this can be done?
Thanks.
Ugly hacky "solution": set top image inset to positive value, bottom inset to equal but negative value.
As MM says, use the item's imageInsets property:
tabBarItem.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
You can try to use UIToolBar instead of UITabBar. UIBarButtonItem has method initWithCustomView. This is more complicated but may work properly.
i created a UITextField of type rounded textfield, using Interface Builder,so in order to set the Height of a textfield its window was disabled(not to set any height manually) in SizeInspector.so if we want to set height manually,what procedure should we follow.
One thing i would like to mention is ,we can do that in coding part,but what i would like to know is ,how can we acheive that in interfacebuilder.
Answers from you were always appreciated.
Change the border style, like this:
Unfortunately you can't set the Height of a UITextField using Interface Builder. You will have to set it programatically and be sure it doesn't break any rules from iPhone Human Interface Guidelines
You can change the height of UITextField by editing the .xib file. Just open it using Textedit or Dashcode and search for the IBUITextField. Edit to NSFrame parameter to whatever size u want.
increase the size of the font and the box's height will increase
Change the Border Style property of the text field to something other than the rounded rectangle. After that you can freely set the height of the box.
Right click on .xib file and click on "Open As"-> "Source Code". Then search for UITextField's NSFrame. Change the height as you want.
Successful solution with my condition:
After trying all above ways, I could not change the height of UITextField.
Finally, I found out that I put UITextField in stack view (or it was affected by some constraints).
So, I added Height Constraint for UITextField then put my expected height in Constant of Constraint.
And it works.
Specially, it works for all Border-style (None, Line, Bezel, RoundedRect).
No code is needed.
After a bit of playing around, I realized that UITextField can be thought of as a UIButton (Rounded rect style) with a UILabel on top of it. Or, it is a UITextView on top of UIButton Rounded rect style. The number of lines, dimensions and position of the label inside the button can be easily adjusted in IB.
In my case, I wanted a read only text-field so I used UILabel on top of UIButton. I adjusted the size of button as per requirement and also label size. I also had to uncheck the 'Enable' box for the button in IB so that it does not get highlighted on touching.
You can easily change that using source code. Just right click on your storyboard, open it as source code, then search for your text field and change the height.
The easiest way that i have found to accomplish this is to change the border style and then edit the other attributes to your liking. Here's an example.
emailField.layer.borderColor = [[UIColor blackColor] CGColor];
emailField.layer.borderWidth = 2.0f;
emailField.layer.cornerRadius = 8.0f;
emailField.alpha = .75f;
emailField.layer.backgroundColor = [[UIColor whiteColor] CGColor];
!
I resolved textfield (with rounded rect) height problem. You must define height constraint for your textfield object.
Define height constraint for Textfield.
We can change height of Text Field with any type of border style other than rounded rectangle by simply dragging. But for the Rounded Rectangle Text fields it is not possible...of course we can change height using some code.
And here I found a simple way. It worked for me
Select the text field and at the below right corner we can see the pins option..
There select the height constrain it is 30 pre-defined...
select that height and you can see "Add 1 Constraint" is enabled.
Click on that..therefore we have added height constraint for that text field.
Now go to the size inspector. There find the Height constraint in "Constraints"...which is above the "Content Hugging Priority"
You can edit the height there...give whatever value you want to give. Now see the textfield it is changed to its height which you have given.
It worked for me :) Can use this scenario for UISwitch, Segment, etc..
As #peterdoesco.de said, Just add an Height constraint, and change it's value, this can works fine.