I use a self.navigationItem.titleView and I set two UIButtons as the self.navigationItem.rightBarButtonItems in the UINavigationBar. I have achieved this in my navigationBar like so
Whenever I rotate the view controller landscape and then back, the uibarbutton item gets cut off like so
The code I use to set the titleView is this:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.numberOfLines = 2;
titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];
titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = self.tabTitle;
self.navigationItem.titleView = titleLabel;
I have no idea why this is happening and I wonder if if any of you know how to fix this.
Related
I have the code likes, in the title bar I am having 3 buttons, left search button, right camera button and option button, in between I am having title.
What I want to do is, I want to display the title centered between the search button and Camera button, can anyone help me how to do this.
//Left Button
UIBarButtonItem *leftSearch = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"btn_search"] style:UIBarButtonItemStyleBordered target:self action:#selector(gotoSearch)];
leftSearch.imageInsets = UIEdgeInsetsMake(0, -5.0f, 0, 0);
[leftSearch setTintColor:[UIColor whiteColor]];
/////////
//Right Button -- First Camera
UIBarButtonItem *rightCamera = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"icon_camera"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(gotoPhotoGallery)];
[rightCamera setTintColor:[UIColor whiteColor]];
rightCamera.imageInsets = UIEdgeInsetsMake(0, 0, 0, -59.0f);
///////////////////
//Right second Button -- for options menu
UIBarButtonItem *rightMenu = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"header_option"] style:UIBarButtonItemStyleBordered target:self action:#selector(gotoPhotoGallery)];
[rightMenu setTintColor:[UIColor whiteColor]];
rightMenu.imageInsets = UIEdgeInsetsMake(0, 0, 0, 5.0f);
///////////////////
NSArray *buttons = #[rightMenu, rightCamera];
self.navigationItem.rightBarButtonItems = buttons;
[[self navigationItem] setLeftBarButtonItem:leftSearch];
//Title Label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:#"Museo Sans" size:20];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = LoginUserName;
self.navigationItem.titleView = label;
[label sizeToFit];
Create your title label with the same width and height as the navigation bar. For example
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,44)];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = LoginUserName;
titleLabel.textColor = [UIColor whiteColor];
[self.navigationController.navigationBar addSubview:titleLabel];
This will put your text in the middle.
The inputAccessoryView is shown successfully, but it is totally black.
_textField = [[UITextField alloc] initWithFrame: CGRectZero]; // update frame later
_textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
UIView *inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 180)];
inputAccessoryView.backgroundColor = [UIColor blackColor];
inputAccessoryView.alpha = 0.2;
_textField.inputAccessoryView = inputAccessoryView;
I am completely confused over this... can anyone explain why it happens?
Use This method of UIColor on previous line instead of setting alpha:-
[UIColor colorWithHue:saturation:brightness:alpha:];
I am trying to create a view in iOS to let the user know their data is loading... it should have about a 200x200 Rounded-corner box in the middle with a spinner and the words "Data Loading..." and a transparent background.
This all is working except my 200x200 rounded-corner box is also transparent.
Here is the code I am using:
UIView *loadingDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 367)];
loadingDataView.alpha = 0.4;
loadingDataView.backgroundColor = [UIColor clearColor];
UIView *viewWithSpinner = [[UIView alloc] initWithFrame:CGRectMake(110, 106, 100, 100)];
[viewWithSpinner.layer setCornerRadius:15.0f];
viewWithSpinner.backgroundColor = [UIColor blackColor];
UILabel *msg = [[UILabel alloc] initWithFrame:CGRectMake(5, 75, 90, 20)];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5, 5, 90, 70)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[spinner startAnimating];
msg.text = #"Data Loading";
msg.font = [UIFont systemFontOfSize:14];
msg.textAlignment = UITextAlignmentCenter;
msg.textColor = [UIColor whiteColor];
msg.backgroundColor = [UIColor clearColor];
viewWithSpinner.opaque = NO;
viewWithSpinner.backgroundColor = [UIColor blackColor];
[viewWithSpinner addSubview:spinner];
[viewWithSpinner addSubview:msg];
[loadingDataView addSubview:viewWithSpinner];
[self.view addSubview:loadingDataView];
Thanks.
No exactly an answer to your question, but check out the open source MBProgressHUD. It aims to be an open source replacement for the private UIProgressHUD class, and is exactly what you're trying to do.
The solution for your problem is that you should remove the alpha attribute of 0.4, that's what's turning your round view transparent, if your view is set to clearColor (this is not really a color, it just makes the view transparent) it makes no sense to add an alpha of 0.4. If what you want is a semi-transparent view surrounding your black rounded view, you should do the following:
[loadingDataView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 andAlpha:0.4]];
That will give you something whiteish kinda grayish, that should work.
However, I would recommend you to use the GIDAAlertView Class I developed, you can get the source and an example app on my GitHub:
It takes about 3 lines to get it working:
GIDAAlertView *spinnerAlert=[[GIDAAlertView alloc] initAlertWithSpinnerAndMessage:#"GIDAAlertView Spinner"];
//Show it ...
[spinnerAlert presentAlertWithSpinner];
//Later in your code, hide it
[spinnerAlert hideAlertWithSpinner];
This is how it looks like.
you are telling it to be clear...
loadingDataView.backgroundColor = [UIColor clearColor];
What do you want it to be black?
I am making a custom backBarButtonItem with a PNG and that works just fine. The only question is how to change the text color. The way I did that on my navigation bar was this:
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"aColor.png"]];
self.navigationItem.titleView = label;
label.text = #"aTitle";
dont use autorelease for set label to titleview,after assign them release them
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"aColor.png"]];
label.text = #"aTitle";
self.navigationItem.titleView = label;
[label release];
I'm diving into iOS development and I'm programmatically creating some labels, but I can't seem to set their background color to black. From what I read, it seems simple enough, here's my code...
UILabel *lbl = [[[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height] autorelease];
[[lbl layer] setBorderColor:[[UIColor blackColor] CGColor]];
[[lbl layer] setBorderWidth:1.0];
[[lbl layer] setBackgroundColor:[[UIColor blackColor] CGColor]];
[[self view] addSubview:lbl];
When I do this, the border color and width work as expected, but the background color remains white. Am I forgetting to do something?
Thanks so much for your help!
A UILabel already has a .backgroundColor property, you don't need to tweak its layer...
lbl.backgroundColor = [UIColor blackColor];
setting background color of UILabel
[lbl.backgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"color_lightblue.png"]]];
setting TextColor of UILabel with image color
[label_Description setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"color_lightgray.png"]]];
simple background color
lbl.backgroundColor = [UIColor blackColor];
swift 2
label.backgroundColor = UIColor.whiteColor()
other formula:
let label = UILabel(frame: CGRectMake(0, 0, view.frame.width, view.frame.height))
label.backgroundColor = UIColor.whiteColor()
label.textAlignment = NSTextAlignment.Center
label.text = message
label.numberOfLines = 2
label.font = UIFont.systemFontOfSize(12)
lbl.backgroundColor = [UIColor blackColor];
Use this
with one code you can set color
LabelObj.backgroundColor = [UIColor blackColor];