Left-aligned text at viewDidLoad instead of center with custom font - iphone

I'm using a custom font on an iPhone app. This font is used on UIButtons and is displaying well.
In IB, I'm setting up horizontal alignement to center and changing the font programaticly with :
[self.playButton.titleLabel setFont:[UIFont fontWithName:#"myfont" size:30]];
when the viewDidLoad is reached.
On the screen, when the view appear, the button's label is first left-aligned in my button and then, 1/2 sec later, it switch to center like I want.
It looks really strange ... if anyone have a clue about this, thanks a lot !
EDIT:
When using
[self.playButton.titleLabel setTextAlignment:UITextAlignmentCenter];
It's nearly the same, the text is cut and then appears totaly.

I am having EXACTLY the same problem. It appears using (sorry for the code, is Xamarin.iOS's C#, not obj-c) UILabel.Appearance.Font = UIFont.FromFile... Removing that let me set font even in the ViewDidLoad!

Related

Font Issue in iPad

I am working with custom fonts. it is working fine with iPhone
[btnHourMins.titleLabel setFont:[UIFont fontWithName:#"Rockwell-Bold" size:18]];
[txtPrice setFont:[UIFont fontWithName:#"Rockwell-Bold" size:18]];
but when i used it in iPad then it display strange behavior (see in image), it display only half of the textbox an button.No any type of frame of button or textField set by me.
my coding for ipad is
[txtPrice setFont:[UIFont fontWithName:#"Rockwell-Bold" size:36]];
[lblHourMins.titleLabel setFont:[UIFont fontWithName:#"Rockwell-Bold" size:36]];
and if i set the size 10 instead of 36 it works fine. I download font from heare http://www.freefontsdb.com/detail/8042/Rockwell-Bold How can i solved this Problem. I searched from last 2 days.
1) No any type of view above on UITextField of UIButton
2) NO any type of frame set by me in coding (I just set the font).
3) Size of the Textfield and button is very bigger.
When i set backgroundclour Pink it display ...
Looks like the frame of your label isn't tall enough for the size of the font.
You will need to adjust the height to see the full text, or have it shrink the fontsize based on what will fit in the label.
Edit:
Sorry I didn't see the additional text after your picture. Can you verify that the view is big enough? Try setting the background color to see it's frame.
I Found the solution. its the problem of font file when i tried with this
http://www.2shared.com/file/DEGKglFX/ROCKB.html
It working fine.

iOS 5 UIButton title showing with ellipsis

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.

How to use colorWithPatternImage: with UILabel

I am trying to create a UILabel with customized text that shows the current score of a game. The customer has given me screen shots where they would like the color/pattern of the text to be like that of a wooden panel, so it looks to be brownish with darker swirls within it.
Is this even possible? I have spent an enormous amount of time scouring the web for something related to this and have found nothing concrete. One lead I followed that didn't pan out was using:
[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed: #"WoodenPanel.png"]]];
It seems like there's a way to use an image and set it as the color for the text. But what results when I use this is a completely black UILabel. Is this on the right track? Or is this simply not possible?
You have to do it like this:
[labelName setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"IMAGENAME.PNG"]]];
NOT like you did:
[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"IMAGENAME.PNG"]]];
You have to put the name of the declared label instead of UILabel
Can text in UILabel have a colorWithPatternImage: assigned to it?
It does use the colorWithPatternImage though
What do you mean by it didn't pan out.
Also this is a possible duplicate of the link I just gave you.
It turns out I had actually implemented it correctly. The line of code I provided above was not an exact line out of my program, but more of a generality.
The reason I was getting a completely black font was that part of the particular image I was using was entirely black. It seems that the image isn't scaled down to fit the text and UILabel so what was being revealed was the bottom 1/5 of the image. I did not have to solve this problem as the image provided for me to implement this was a repetitive pattern throughout the image so that any part of the image would produce the desired effect of a wooden panel type color font.

How to set UITextView's content inset like Notes App

I am working in an app in which I need to give feature like Notes App in iphone. as shown in first screen shot , initially , notes leaves a tab before the content starts, I also wanted to do the same and for that when I set Left Content inset (of UITextView) by 25 , it shows like in screenshot 2, here you may see the image also gets shifted. I have set image as background. I don't know how to solve this problem.
I also tried by adding image as subview of UITextview but it won't repeat the lines, while scrolling (image of lines) like notes app.
I'm setting the background of Textview by following code.
[textView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"line_image.png"]]];
Please tell me if I am going wrong or any extra effort needed to get desired output.
Thanks
UITextView is UIScrollView subclass so all relevant delegate method are available for you (e.g. scrollViewDidScroll:) - you can adjust your custom background in that method.
There's very nice post on Dr.Touch blog about recreating Notes app interface - you can get general idea about how it is done from it. Basically what is done there is adding custom view that draws background behind the text view and adjust it in text view's delegate methods and also using KVO on its 'contentSize' property.
#Dinesh gave nice solution but it doesn't sound to be generic as I want to use image of lines instead of drawing them. Image has some special effects that can not be achieved by drawing. So to solve it I created a table view below the textview keeping textview's background transparent. Now just added the image of line to my tableview's custom cell and set content offset of UItableview same as of the scrollview (subview of text view ,refering to the answer of #Vladimir ) .
And used the following code to scroll my tableview with scrolling the textview and got the desired output.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
tableView.contentOffset =scrollView.contentOffset;
}
Keeping my tableview's number of rows at a very large number.
PS: instead of setting the content inset of textview, i set its frame's X position and decreased the width relaively.

How to type a text in imgeview. Right now sucessfully drawing using mouse

How to type a text in imgeview... right now successfully drawing using mouse. I need to type text in same image view using keyboard...
Try superimposing a UITextView on top of your UIImageView and set appropriate frames for both so that the text appears until where you want it to appear.
Set this property for your UITextView
myTextView.backgroundColor = [UIColor clearColor];
myTextView.textColor = [UIColor redColor]; //or whatever color you like based on the background image in your UIImageView.
Of course you will have to take care of the scrolling when the keyboard comes up after the UITextView becomes active.
If you want more assistance, please elaborate upon your question and your need.