UITextView - how to make it look like in the IB? - iphone

I am initializing a text view from my code, not from the interface builder and it appears to be just a white rectangle. I want it to have the same rounded shape as is in the interface builder. How can I achieve this?
The same question concerning UITextView.
Thanks.

The text view is rectangular even in IB. A UITextField has rounded corners. For that, just set the borderStyle property of UITextField to UITextBorderStyleRoundedRect

You maybe confusing UITextView with UITextField.
UITextField has a optional rounded rectangle border. UITextView is just the text, no border. You have to bring your own border to the party and place it behind the UITextView.

Related

UIButton Title not showing inside UIStackView

I created a UIStackView with a UIImageView and a UIButton. The text inside of the UIButton won't show. I can tell that autolayout works because the background and the selection of my UIButton both work properly.
The title always disappears when I have the constraints on. I set the image to 0/0/0/0 without margins and aligned the button to the image's edges.
Has anyone run into this or knows how to fix it?
At the end I simply used a UIView. I don't know what made me use the UIStackView but I guess it's not made for overlaying objects.

Outline text/font in UIButton

I'm working on a project where UIButtons can have their font color dynamically set depending on user settings. To avoid the issue of a light font on a light background or a dark font on a dark background I'd like to outline my font with a thin, black outline. I'm talking about an outline directly around the letters, not around the label or button itself. Something like the typical LOLcat Impact font outline: http://mintyferret.com/wp-content/uploads/2007/07/lolcat7.gif
Does anyone have an example of this in action? I'm open to suggestions if you have something easier, but I'm not really in a place where I want to create custom images for my buttons. They can have dynamic text and dynamic colors, so I need it to be pretty flexible.
UIButton contains its title in a UILabel and UILabel has no option to add borders around your characters. The titleLabel property of UIButton is read-only, so you can't replace it with your own UILabel subclass. Therefore, the only option appears to be to draw the text in the button's drawRect function.
Here's a topic on how to draw borders around text:
How do I make UILabel display outlined text?
I'm pretty sure you'll have to override the setTitle:forState: and currentTitle functions using your own variables, or the button will draw text behind or in front of the text you draw.

Is there a way to put UITextView's scroll indicator to outside UITextView?

It might be a silly question.
I'm trying to set left/right margins like the attached picture. I succeeded to implement it by adding UITextView to UIScrollView.
However, I could achieve almost everything I want with UITextView alone. For example, with UIScrollView, when I manually change the text of UITextView, it automatically scrolls to bottom regardless of setting its .scrollEnabled to No.
It would be perfect if a scroll indicator of UITextView appears outside UITextView.
In the attached picture, let's say the red box represents the entire UITextView. I tried to change UITextView's scrollIndicatorInsets property, but a scroll indicator can be moved only inward to be visible.
Several apps such as Pages, aWriter, Plaintext achieve this feature.
Could you give any suggestion?
Thank you!
I
You can set the scroller right inset value of the UITextView to negative value and disable the clip subview option to achieve your require. No other scrollview is needed.
Alternatively you could set the Right contentInset property.
UIEdgeInsets insets = textView.scrollIndicatorInsets;
insets.right += 5; //add what ever is your margain
textView.scrollIndicatorInsets = insets;

Rounded UIBarButtonItems

I need to make UIBarButtonItem rounded. In xib even though the style attibute specified as bordered it displays a rectangular shape. Is there any work around to achieve this?
Regards,
Dilshan
Try to use initWithCustomView:(UIView *)customView where the customView is a custom UIButton with a round image.

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.