Remove background of UIVIew - Remove The rectangle like shape - ios

I have a UIView in which i want to remove the whole background so it would take the shape of a paper. I tried setting the background to transparent from the UI and using the code but i always end up with a gray-like semi transparent background no matter what i do. Here is the current output i am getting :
How can i remove that grey background? i need it to display as a whole paper without that residue. Any Help? I tried the following :
// self.view.backgroundColor = [UIColor clearColor];
//
// [self.view setOpaque:YES];
//
// self.view.backgroundColor = [UIColor clearColor];.
// self.view.layer.borderWidth = 0.0;
// self.view.layer.masksToBounds = YES;
// self.view.backgroundColor=[[UIColor clearColor] colorWithAlphaComponent:.0];
And the current UI Configuration is :
How can i manage to remove it !? Any help!?
EDIT 1
This is the new output

Looks like your image it's inside a Modal View. If that is the case try the following:
Set the self.view.superview.backgroundColor to [UIColor clearColor]; inside the viewWillLayoutSubviews
Example
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.layer.masksToBounds = YES;
self.view.superview.backgroundColor = [UIColor clearColor];
}

Related

iOS: How to achieve the same highlight that a UIButton background image has?

I am trying to achieve the same highlight that a UIButton background image has, but for a UIButton with no background image. This is what it looks like when the UIButton with an image background has been highlighted.
However, I am unsuccessful achieving this when using a non background image button. This is the code I have so far for my custom button.
- (void)setHighlighted:(BOOL)highlighted
{
if (highlighted) {
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.9f];
self.titleLabel.alpha = 0.9f;
} else {
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:1.0f];
self.titleLabel.alpha = 1.0f;
}
[super setHighlighted:highlighted];
}
The main problem is it isn't dark enough. Is there a way I can change the background color and label color to resemble a UIButton with an image background that has been highlighted?
Edit: I know alpha makes it lighter, but this was recommend in a thread when I was researching.
Edit: I created this method
- (void)setHighlighted:(BOOL)highlighted
{
if (highlighted) {
if (!overlayView) {
overlayView = [[UIView alloc] initWithFrame:self.bounds];
overlayView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
}
[self addSubview:overlayView];
} else {
[overlayView removeFromSuperview];
}
[super setHighlighted:highlighted];
}
This seems to work well, but not sure if there is a better alternative.

Navbar colour doesn't look right

I've set my navbar to white or atleast tried to. However, it hasn't come out looking very white it seems.
Here's the bit of code where I set it.
- (void)viewDidLoad {
[super viewDidLoad];
[self addSidebarNavButton];
// Set the navbar
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *nav_titlelbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.navigationItem.titleView.frame.size.width,40)];
nav_titlelbl.text=#"";
nav_titlelbl.textAlignment=NSTextAlignmentCenter;
UIFont *lblfont=[UIFont fontWithName:#"Futura-Medium" size:20];
[nav_titlelbl setFont:lblfont];
self.navigationItem.titleView=nav_titlelbl;
// Set the navbar colour
self.navigationController.navigationBar.barTintColor =
[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0];
self.navigationController.navigationBar.translucent = YES;
Unfortunately I can't attach the navbar image here as I don't have the 10 reputation points needed. However if I could, you'd see that the navbar in question comes out looking light gray!
Set self.navigationController.navigationBar.translucent = NO; you might be seeing the view background.

Change background color on textview dynamically

i'm having an edit button which is connected to this method. In this method i want to make the textView editable and change the background. The problem is the background do not seem to change. Why is that?
ViewDidLoad
self.aboutText.backgroundColor = [UIColor clearColor];
self.aboutText.delegate = self;
self.aboutText.editable = NO;
method
-(IBAction)editField:(id)sender {
self.aboutText.backgroundColor = [UIColor whiteColor];
self.aboutText.editable = YES;
}
Okay the issue was i only did set the action and not the target.
All i did was set the target to self.
sorry for the inconvenience
Try the following:
//.h file
#interface AddEntryViewController : UIViewController<UITextViewDelegate>{}
//.m file
//viewDidLoad
_aboutText.delegate = self;
//add the following method
-(void) textViewDidBeginEditing:(UITextView *)textView
{
[textView setTextColor: [UIColor blackColor]];
}

Decrease opacity of UIView in IOS 7

I want to create an UIView user interface design with some transparency as i have mention in first image:
First Image :
here is my code :
self.view.opaque = NO;
self.activityIndicatorView3.alpha = 0;
[self.view addSubview:self.activityIndicatorView3];
[self.activityIndicatorView3 startAnimating];
self.activityIndicatorView3.alpha = 1.0;
self.view.alpha = 0.15;
Using above code i am getting output as below output image :
here progress bar is not visible. I don't know, what i am doing wrong in my code. Please help me to achieve this. Thanks!
Actually you added the activity indicator in View.So if your decreasing the alpha of view,It will effect to its subviews also.For this you can use
self.view.opaque = NO;
self.activityIndicatorView3.alpha = 0;
[self.view addSubview:self.activityIndicatorView3];
[self.activityIndicatorView3 startAnimating];
self.activityIndicatorView3.alpha = 1.0;
self.view.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:.6];
You can reduce the alpha of view background color .
Setting the opacity for the superview will also affect its subviews.
The best way is to create a faded view for that effect
self.activityIndicatorView3.alpha = 0;
[self.view addSubview:self.activityIndicatorView3];
[self.activityIndicatorView3 startAnimating];
self.activityIndicatorView3.alpha = 1.0;
// Change this self.view.alpha = 0.15; to following code
UIView *fadedView=[[UIView alloc]initWithFrame:self.view.bounds];
[fadedView setBackgroundColor:[UIColor blackColor]];
[fadedView setAlpha:0.15];
[self.view addSubview:fadedView];
[self.view sendSubviewToBack:fadedView];

is groupTableViewBackgroundColor deprecated on iOS 6?

I was just testing my app with iOS 6.0 and Xcode 4.5GM and I have set up a view like this:
[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
So, the view has the same pattern than a common table view.
This works fine on iOS 4 and 5, but in iOS 6 it just gives me a white background.
Is this deprecated? If so, how can I replace it?
Thanks
This method will be deprecated during the 6.0 seed program
If you want to have a background in your own view that looks like the table view background,
then you should create an empty table view and place it behind your content.
First, add this to your viewDidLoad:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableViewBackground.png"]];
OR
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableViewBackground.png"]];
Then add this images to your app:
tableViewBackground.png
tableViewBackground#2x.png
I've written a UIColor category to replace groupTableViewBackgroundColor:
#interface UIColor (UITableViewBackground)
+ (UIColor *)groupTableViewBackgroundColor;
#end
#implementation UIColor (UITableViewBackground)
+ (UIColor *)groupTableViewBackgroundColor
{
__strong static UIImage* tableViewBackgroundImage = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(7.f, 1.f), NO, 0.0);
CGContextRef c = UIGraphicsGetCurrentContext();
[[self colorWithRed:185/255.f green:192/255.f blue:202/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(0, 0, 4, 1));
[[self colorWithRed:185/255.f green:193/255.f blue:200/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(4, 0, 1, 1));
[[self colorWithRed:192/255.f green:200/255.f blue:207/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(5, 0, 2, 1));
tableViewBackgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return [self colorWithPatternImage:tableViewBackgroundImage];
}
#end
This solution also allows to tweak the appearance of the background. Feel free to change the drawing code :)
In iOS6 SKD, comments in UIInterface.h suggest the following:
Group style table view backgrounds can no longer be represented by
a simple color.
If you want to have a background in your own view
that looks like the table view background, then you should create
an empty table view and place it behind your content.
This method will be deprecated during the 6.0 seed program
A simple solution is to set the background with equivalent RGB values:
[self.view setBackgroundColor:[UIColor colorWithRed:215.0/255.0 green:217.0/255.0 blue:223.0/255.0 alpha:1.0]];
You can them set the view background to color to White or whatever you like in the xib to suppress the warning.
If it helps anyone, here's specifically what I'm doing in my custom view to get this background (using hint from Mr Beloeuvre)
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
[self.view addSubview:tv];
[self.view sendSubviewToBack:tv];
// ...
}
Try this:
[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];
You may have difficult time to locate the view if you use storyboard and have many views. You can click on "Show the Version editor" button the right top corner. This will change story view to XML text view. Search for "groupTableViewBackGroundColor". You should find views with this attribute.
It's good idea to use standard methods for previous iOs versions. So I improved solution of James Boutcher:
+ (void)setBackgroundColorForTableView:(UITableView*) tableView
{
UIColor* color = [UIColor whiteColor];
NSString* version = [[UIDevice currentDevice] systemVersion];
if([version floatValue] < 6.0)
{
tableView.backgroundColor = color;
}
else
{
tableView.backgroundView = nil;
UIView* bv = [[UIView alloc] init];
bv.backgroundColor = color;
tableView.backgroundView = bv;
[bv release];
}
}
Elaborating on #NSElvis's solution, here is the identical grouped table view background asset (it's wide enough so you don't get funny effects in landscape orientation)
back-tableview#2x.png
To use it, simply do
[YOUR_VIEW setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"back-tableview"]]];

Resources