Table View Header Section not being transparent - ios

I am setting up a UITableView header view and would like this to be semi transparent. So that when the table scrolls up for example the top header is still shown but you can partially see the content through the view.
I have one view and one label (adding to the view) for the header view.
headerLabel.textColor = [UIColor colorWithWhite:0.4 alpha:1.0];
headerLabel.font = [UIFont systemFontOfSize:14.0];
[headerSectionView addSubview:headerLabel];
[headerLabel setBackgroundColor:[UIColor clearColor]];
[headerSectionView setBackgroundColor:[UIColor colorWithWhite:0.847 alpha:5.000]];
However, this does not show as transparent. I have tried to remove the label from the subviews of the view but this does still not work so it is not the label causing this. Is there anything else I need to set on the headerSectionView to have this work?

Your alpha value is incorrect, it should be 0.5f, not 5.0f:
[headerSectionView setBackgroundColor:[UIColor colorWithWhite:0.847 alpha:.5f]];

Related

How to shove a label in a tableview full of buttons?

I have a table view full of buttons. A label is outside the tableview serving as heading. I want to shove it inside the table view, on top of course, without changing it to button. In other words I want to move it inside the tableview, but on top and not as a button,as a heading.
The label in question says "Select all things that apply to your home"
For code please see Set title labels of buttons in table view from an array full of strings
For Screenshot pls visit http://i60.tinypic.com/2qmf4wl.png
How about this?
UIView *headerView;
UILabel *labelView;
labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
labelView.font = [UIFont fontWithName:#"Trebuchet MS" size:22.0];
labelView.backgroundColor = [UIColor clearColor];
labelView.text = #"* Your important note here.";
labelView.textColor = [UIColor blackColor];
[headerView addSubview:labelView];
yourTableView.tableHeaderView = headerView;
It's hard to add a label to a tableviewcontroller. Two options I can think of:
Make "Select all things that apply to your home" your navigation item title. (you can do this right in the storyboard)
Place a table view in a normal view controller and leave enough space on top for a label. (again, you can drag a normal table view into a view controller in a storyboard)
Hope it helps!
you can creat a subclass of UITableViewCell and custom the cell for the tabe

ViewController's background color can not be changed in the viewDidLoad

I'm trying to change UIViewController's backgroundColor.
I wrote the code in the viewDidLoad method. My other objects are shown on the screen without any problem but backgroundColor property did not work. The screen is gray. I also tried [UIColor redColor] or to write only this row in the viewDidAppear method but nothing changed.
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:0.15
green:0.15
blue:0.3
alpha:1.0];
//Add start button
[self.view addSubview:[self createButton:#"ButtonSample.png"
setTitleColor:[UIColor whiteColor]
buttonPositionX:(CGRectGetMidX(self.view.frame)-30)
buttonPositionY:(CGRectGetMidY(self.view.frame)+30.0)
buttonWidth:80.0
buttonHeight:20.0]];
//Add game title label
[self.view addSubview:[self createLabel:#"Vecihi"
labelFontName:#"Chalkduster"
labelFontSize:20
labelPositionX:CGRectGetMidX(self.view.frame)-25
labelPositionY:CGRectGetMidY(self.view.frame)
labelWidth:80
labelHeight:20
fontColor:[UIColor whiteColor]]];
//Add game logo imageView
[self.view addSubview:[self createImage:#"Spaceship"
imagePositionX:CGRectGetMidX(self.view.frame)-30
imagePositionY:CGRectGetMidY(self.view.frame)-80
imageWidth:40
imageHeight:60]];
}
I just tested it an it works just fine to set the color of a view controller's content view in viewDidLoad.
In my case, I had a view inside the content view that took up most of the visible area, so very little of my custom color was visible. I had to set the background color of my subview to clear before I could see the changed background color.
Is it possible that you have a subview that completely fills your content view and hiding it's background color?
If that's not the case, try adding a breakpoint to your viewDidLoad method to make sure it's being called.

display the view behind tableView (or scrollView)

For example:
there is a tableView, when it is pulled down, the back view display. the effect is like this:
I tried like this but not working:
[self.view addSubview:logoView];
[self.view addSubview:tableView];
You have to
add your logo image view below the table view in xib.
set table view background color to clear color
Set logo image hidden.
in - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate or check for your self which delegate is best suited. set the logo image hidden to NO
You set the tableView background as your logoview. Keep your UITableviewCell as what color you want.
I'm not sure if i recognize your problem but i think you want something like this:
you'll have to use:
[self.view insertSubview:aboveSubview: ];
[self.view insertSubview:belowSubview: ];
not
[self.view addSubview: ];
You can achieve the same as the example image above by adding the view with a negative y offset.
UIView *header = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f - self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
header.backgroundColor = [UIColor lightGrayColor];
[self.tableView addSubview:header];
However if you have content in this view, such as a logo, it will appear to be pulled down from the top, rather than behind the table, I don't know if this is the effect you want or not.

Need to center placeholder text in custom UITextField vertically in iOS

I am working on an iOS application where I have subclassed my UITextField in order to set the colour of my placeholder text. I have also centered it horizontally, but my problem is that my placeholder text is not centered vertically, and for some reason, the cursor is not centered within the placeholder text, but instead appears just after the very first character of the placeholder text.
My method in my subclass of UITextField which I override in order to set the colour of the placeholder text and center the text horizontally looks like this:
- (void)drawPlaceholderInRect:(CGRect)rect {
// Set colour and font size of placeholder text
[[UIColor whiteColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:28] lineBreakMode:UILineBreakModeMiddleTruncation alignment:NSTextAlignmentCenter];
}
Here is my code where I create and set up my UITextField:
_field = [[CustomTextField alloc] initWithFrame:CGRectMake(190, 300, 644, 64)];
_field.delegate = (id)self;
[_field becomeFirstResponder];
[_field setBackgroundColor:[UIColor darkGrayColor]];
[_field setTextColor:[UIColor whiteColor]];
[_field setPlaceholder:#"Enter First and Last Name"];
[[_field layer] setMasksToBounds:8.0f];
[[_field layer] setBorderColor:[[UIColor grayColor] CGColor]];
[[_field layer] setBorderWidth:1.0f];
[_field setFont:[UIFont fontWithName:#"Arial" size:25]];
[_field setReturnKeyType:UIReturnKeyDone];
[_field setTextAlignment:NSTextAlignmentCenter];
_field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.view addSubview:_field];
I initially subclassed my UITextField because while everything looked fine, my placeholder text for some reason was grey instead of white (which I set as the text colour for the textfield). Ironically, the placeholder text was centered both vertically AND horizontally, AND the cursor was centered. So in order to correct the placeholder text colour, I subclass the UITextField, only to open up more problems now.
Is there a way that I can now center the placeholder text vertically, as well as have the cursor centered as well? Better still, is there a way for me to change the grey colour of the placeholder text to white without having to subclass it? This would be ideal.
I think you forgot to implement in .h ( not in your custom TextField class )
#interface YourView : UIView<UITextFieldDelegate>
and the delegate method didn't called ! The placeholder textcolor must be that color what you want, if you do it like this.
#import "YourView.h"
#implementation YourView
// .....
_field.delegate = self;
_field.textAlignment = NSTextAlignmentCenter;
// ....
You can add some vertical padding like this:
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 30)];
_field.leftView = paddingView;
_field.leftViewMode = UITextFieldViewModeAlways;
from apple developer library:
leftView
The overlay view displayed on the left side of the text
field.
#property(nonatomic, retain) UIView *leftView
Discussion You can use
the left overlay view to indicate the intended behavior of the text
field. For example, you might display a magnifying glass in this
location to indicate that the text field is a search field.
The left overlay view is placed in the rectangle returned by the
leftViewRectForBounds: method of the receiver. The image associated
with this property should fit the given rectangle. If it does not fit,
it is scaled to fit.
If your overlay view does not overlap any other sibling views, it
receives touch events like any other view. If you specify a control
for your view, the control tracks and sends actions as usual. If an
overlay view overlaps the clear button, however, the clear button
always takes precedence in receiving events.
link to apple developer library / UITextField
I hope this helps !

UITableView FooterView background color to clear color doesnt work

i try to set the UITableView Footerview backgroundcolor to clearColor but it stays white, any
other color works fine, any ideas?
_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _incredientsTable.frame.size.width, 60)];
[_footerView setBackgroundColor:[UIColor clearColor]];
Thanks.
Ask yourself these questions:
What do you expect to see through the footer view? Is it the table's background? The underlying view controller's views? In the latter case there are more views between your and the object that you want to be visible under the footer view. That is at least the UITable itself and probably the background of self.view (which in most cases but not all is the table)
You need to set background color of table view in this case.
tblView.backgroundColor = [UIColor clearColor];

Resources