Different opacity for UILabel and the text of the UILabel - uilabel

I have a UILabel whose opacity has been changed to blank by using [UIColor clearColor]
I now want to change the opacity of the text within the label to the full possible level.
How do I do it?

Use the following code to change the opacity of UILabel text
[headerLabel setAlpha:0.5];
Happy coding..:)

Related

UILabel with horizontal padding?

I'm new to ios development and i'm struggling to make something that should be trivial.
I want simple container with background color and single line text inside with padding and i prefer to make it programmatically (no IB).
What i've already tried:
simple UILabel vertical padding is not a problem with fixed height but no horizontal;
also UIView with UILabel as subview - adding background color to UIView and the label is just text sizeToFit;
When i am using UIView with UILabel as subview i've set:
[self.myTestView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
but because i'am using NSLayoutConstraint when i set self.myTestView.translatesAutoresizingMaskIntoConstraints = NO; i don't have proper autoresizing.
If it helps i'am trying this into UICollectionViewCell?
Just for additional information i know this can be achieved with UIButton and using UIEdgeInsets, but i don't want to use UIButton for simple text container.
Does anybody have an idea or direction?
Thanks in advance!
Why you just didn't add constraint to your label inside uiview in IB, with padding what you need?!
http://i.stack.imgur.com/8qTGt.png

How do you vertically align UILabel text to the top now that sizeWithFront is deprecated? ios7

It's been EXTREMELY frustrating trying to vertically align UILabel text to the top. I've search google for hours, and everything I've found has been deprecated.
What is the best way to do this? I've used numberOfLines=0 & sizeToFit... but this doesn't work upon initial loading of the UILabel on a custom TVCell.
Does anyone have a code snippet that works for align UILabel text to the top on a custom cell?
Calculate height of text and set UILabel frame again.
try this-
CGSize maxSize = CGSizeMake(label.frame.size.width, label.frame.size.height);
CGSize labelSize = [label.text boundingRectWithSize:maxSize
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:#{NSFontAttributeName:label.font}
context:nil].size;
[label setFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y, label.frame.size.width, labelSize.height)];

UIButton Title only displays half of it

I've a UIButton that has a custom FONT for the titleLabel attribute.
For some reason on iOS 6.0 it shows only half of the title. I tried increasing the height of the title. but that didn't work.
What am i missing?
Is this my only option?
btn.titleLabel.font = [UIFont fontWithName:#"Frutiger95-UltraBlack" size:17];
This is how it should look (minus the color change)
Single line labels have a low content compression resistance priority on the vertical axis. So when you increase the font size, they don't increase the height of their intrinsicContentSize. Setting the compressionResistancePriority to UILayoutPriorityDefaultHigh or UILayoutPriorityRequired should fix it.
[btn.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
I think updating the label is enough, but you may need to increase the priority on the button itself as well.
[btn setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
I think you need to set button title nil, then make your own custom UILabel
and add that label on your button like my example given below-
UILabel *lblloginbtntitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, btnLogin.frame.size.width, btnLogin.frame.size.height)];
lblloginbtntitle.text=NSLocalizedString(#"Login", nil);
lblloginbtntitle.textAlignment=NSTextAlignmentCenter;
lblloginbtntitle.textColor=[UIColor whiteColor];
lblloginbtntitle.font=[UIFont fontWithName:#"AvenirNextLTPro-Regular" size:20];
[btnLogin addSubview:lblloginbtntitle];
[btnLogin setTitle:#"" forState:UIControlStateNormal]

How to set an upper border/separator line in ios?

I have an imageview and a label, I want a border in between them, what is the best approach?
I know that the following code creates a border around the whole imageView:
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
But I only want a line below it, not around the whole thing.
Just add an UILabel with background color as black(Assuming your border color as black) and height of 1px between you UIImageView and UILabel this would be much simpler.

Dynamically Resizing a CGRect based on UITextView

Okay I'm not really sure how to explain this. But here goes. I have a UITextView with content that is dynamically populated. I have worked out how to resize automatically depending on the amount of text within it. It could be one line it could be 10.
Now I have a UIView that I have customised which has a rounded Rect code below.
The .h file
#interface roundedEdges : UIView
{
}
The .m file
- (void) drawRect:(CGRect)rect
{
CGRect frame = self.bounds;
UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:frame cornerRadius:8.0];
[[UIColor whiteColor] setFill];
[path fill];
}
What I would like to do is make the rounded UIView to be constrained to the height of the UITextView.
Currently the UITextView is sitting on top of the UIView. This way it provides a rounded box effect.
IS there a way to resize the above code (UIView) to be constrained depending on how much text is coming into the UITextView?
If so how?
Thanks in advance!
Jeremy
To dynamic change in height or width of textView or label depends upon the text size this code is working fine........
I have used this code for both UITextView and UILabel
CGFloat heightTXT = [[txtView text] sizeWithFont:txtView.font constrainedToSize:CGSizeMake(txtView.frame.size.width,INFINITY) lineBreakMode:UILineBreakModeWordWrap].height;
[txtView setFrame:CGRectMake(txtView.frame.origin.x,txtView.frame.origin.y,txtView.frame.size.width,heightTXT];