UIButton title label transform cuts off label - iphone

I am creating a UIButton with interface builder of size 30px width and 164px height.
I want to rotate title of UIButton to 90 degrees.
I am using following code for rotation
// leftNavBtn1 is a UIButton
self.leftNavBtn1.titleLabel.transform = CGAffineTransformMakeRotation(-M_PI / 2);
The problem is after rotation the label cuts off. I have tried to programatically set title but its not work.
I want to achieve like this
What i am getting

The titleLabel property is primarily used to configure the text of the button, not its bounds.
I don't think you can achieve what you want to achieve.
If I understand you correctly, you make a button with a small width and big height in interface builder, then set the transformation on the label of the button to 90º, and then expect the button to behave as if the width became the height and vice versa.
I suppose you could still set the button in interface builder, but make it horizontal, as if it's rotated -90º, and then set the transformation on the UIButton in viewDidLoad

Maybe it's stupid, but have you tried creating a label over your button and then apply the same rotation?
It's not elegant but can work

Related

iPhone - How to partially hide the subview?

I am developing one sample application using gestures, where i can pinch, pan and rotate. I have one main image view width and height is 300 and origin x is 0 and y is 70. This imageview I am using from interface builder. After this i am adding one label programmatically on the middle of the imageView. After adding the label I can able to pan, pinch and rotate the label on the view. Now the actual requirement is when i drag the label outside the imageview I should be display the partial label, for example (My label text is ABCDXYZ). As soon as I drag the Z outside the Z should be invisible, other part ABCDXY should be visible. More clear is drag the one view inside other view. How can i achieve this.
What you have to do is create a UIView. On that add the UIImageView like
[View addSubView:ImageView];
then add the UIlabel on the UIImageView like
[ImageView addSubView:Label];
Now set the clipsToBounds = YES. I think now your issue of the partial label would be solved as the label would move within the UIView and as soon as it goes out it would be shown partially. Any doubt please tell . Thanx :)
Its really tricky to give handheld solution for this, instead it could be a suggestion. I assuming that your UILabel text is dynamic, there's some scenarios you can follow to achieve this.
1) When you touch your label inside UIImageView you shoud get the exact coordinates of it.
2) Get the position where user touch on UILabel.
3) Compare the touch coordinates with total coordinates of UILabel.
4) Assume which character did touched. (You should make test of it, also text size may also matters).
5) When user drag that particular character (say Z) you need to remove that from UILabel text.
That's all. You're done.

Double border to a UIButton

I have to display a UIButton like in the following image. Button size can be varying. How can I do that? Please suggest a way.
If you just want a simple outline (it's a little hard to tell from your image what the button is), create the button with UIButtonTypeCustom (so you get a blank slate) then set its background color to be black. next, get the CALayer of the button (through the layer method) and set the borderColor and borderWidth properties as desired.
make a view and set it's color a bit darker than your desired button color, then make a button a bit shorter than the view size and place it as your fit position, check n tell me if it helps youe

How to auto rotate your own custom views?

I've learned that the best way to get graceful rotation is to set the auto rotation mask on the view that you want resize or move. This works fine if you're using SDK views like UILabel, but if you have your own custom view that uses the drawRect method it doesn't rotate as gracefully. In fact the only thing that happens is that it stretches whatever you drew in drawRect.
I've tried redrawing both before and after the rotation, but it doesn't give me that smooth rotation.
I looked at a UITextField auto rotating (flexible width) in slow motion and it follows the edge perfectly during the rotation. That is what I want my view to do, so how do I do that? My views jump to the right position either before or after the rotation.
The following line will make your UIView stretch the middle pixel only. If this is not your desired behavior I suggest you read the documentation for contentStretch to learn how to manipulate the values of the CGRect.
[self setContentStretch:CGRectMake(0.5, 0.5, 0.0, 0.0)];
I would guess that the UITextField you're looking at has at least three subviews, one displaying the left cap of the field's border, one displaying the right cap, and one displaying the middle, with autoresizing masks of "flexible right margin", "flexible left margin", and "flexible width", respectively. If you set up your custom view something like that, and make sure its autoresizesSubviews property is set to YES, then you should get the same smooth resize that the text field does.

Creating a UIView in Interface Builder that automatically centers itself when added as a subview

I created a UIView xib in Interface Builder and tried everything I could to indicate that the UIView should center itself, anchor itself at center, orient itself in central coordinates, etc. etc.
But whenever I add it as a subview in code, I also have to programmatically set its frame up with CGRectMake() or else it will always add to the top-left of its parent. The math to reframe it is pointless and ugly, so I presume I'm just not twiddling a bit in the IB inspector correctly.
Can anyone confirm this is possible, and if so, what I need to do in IB to accomplish this?
Why don't you just set .center of the subview just added, to be the point created by halving the width and height of the superview?
Either that or define the rectangle that view is going into with IB (I'm imagining a container view) and simply set the frame of the view you are adding to containerView.bounds (bounds is a position independent value and so x,y will be 0 while size will equal the container size.
Centering but maintaining size isn't possible in IB. Centering but maintaining margins to its superview is though.
You will have to override the layoutSubviews message or simply keep the calculation code you wrote.

How to set height for a textfield in size inspector

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.