iOS - Button background changes with gradient background on iPad - ios

I have one view and on view several buttons. I have added a gradient background to view and background image to buttons. But my button's color is changing as gradient background goes down on iPad 6.0.
I have tried to add gradient background to view using both programatically and by adding a gradient image to view by:
CAGradientLayer *bgLayer = [BackgroundLayer greyGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
And
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"keyboard_BG.png"]];
But nothing is working.

But my button's color is changing as gradient background goes down on iPad 6.0.
It sounds like the background image you're using for the buttons is semi-tranparent. Try removing the image, and instead setting an opaque background color. If that works, you'll probably need to edit the background image to make it fully opaque.

Related

View controller with background image and transparency xamarin

I kind of stuck with a design issue in iOS.
I have a controller with a background image, nothing special.
this.View.BackgroundColor = UIColor.FromPatternImage (UIImage.FromFile ("Images/ballons.jpg"));
On top of the controller I have a view with a background color (white) that is semi-transparent.
this.Frame = new System.Drawing.RectangleF (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
this.BackgroundColor = UIColor.White;
this.Alpha = 0.5f;
Now the issue is if I add a button or any other controls in my view they also becomes transparent...so am I thinking wrong here...?
I would like the controller to have a background image, the view a white semi-transparent background and all the controls (buttons, images) not to be transparent at all...
Do not change the Alpha of the view, since that will change the transparency of all its elements/subviews. Just set its BackgroundColor to a semi-transparent color using UIColor.FromWhiteAlpha(1, 0.5).

XCode iOS custom view color

I've a UIViewController and in the main root view I've created a custom class and in drawRect I've created a layer with gradient color and added to it:
[self.layer insertSublayer:bgLayer atIndex:0];
I want to use this view to have the same background color to all my view.
Now, i've (in storyboard) added 5 labels and grouped together in a view (Editor -> Embedded In -> View).
So now I've created another subclass of UIView and in draw rect I have:
[self setBackgroundColor:[UIColor redColor]];
(for now I have simple red color, later I want to had shadow, border ecc)
Because I want that this subview (with the 5 labels) is red (sure, the background must remain gradient).
When I run the application I see the background correctly but the view that I've set the color red is display totally black.
If in storyboard I change the background to Clear Color (in the view that should be red), the 5 labels come in and the background is the same of the main view.
I've placed a breakpoint to drawRect of the "red view" and this is called but nothing happen.
I'd suggest you take a look at Appearance Proxies. You can do what you're looking to do more easily with them.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[MyCustomView appearance].backgroundColor = [UIColor clearColor];
...
}
Also, you likely shouldn't be adding sublayers in drawRect, especially if your views don't move or resize. I typically just add them in -(void)awakeFromNib.
Edit:
To address your question directly, I find the best way to create a gradient background in a custom view is to override +(Class)layerClass to provide a gradient layer. What this will do is make the fundamental layer for your custom view be whatever layer class you return. Typically this may be a shape layer for instance (for a solid color). In our case, we want a CAGradientLayer. Then in -(void)awakeFromNib you can set your gradient colors without mucking about with sublayers.
What I'm guessing is your original issue is that you're adding a gradient sublayer without setting start and end colors which will draw on top of your background color as black.
Example:
#implementation MyCustomView
+ (Class)layerClass {
return [CAGradientLayer class];
}
- (void)awakeFromNib {
CAGradientLayer* gradientLayer = (CAGradientLayer*)self.layer;
gradientLayer.locations = #[#0, #1];
gradientLayer.colors = #[(id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor];
}
Let me know if you need more details or this isn't working for you.

PageControl backgroundColor when used in UIPageViewController

I'm trying to implement a simple tutorial using UIPageViewController in iOS7. I implement all methods in UIPageViewControllerDataSource and it gives me a UIPageControl. Everything works except that the pageControl's background is not transparent so it blocks part of the other views behind it.
I try to change the pageControl's appearance with the following code
pageControl.backgroundColor = [UIColor greenColor]; //works, background is green
pageControl.backgroundColor = [UIColor clearColor]; //not working, background is black.
//updates
It turns out that the black color is the background color of the PageControl's layer. And this Page Control layer is not on top of my own ViewControllers that I used for pages. They are in parallel.So no matter how I modify its colors, I cannot get my ViewControllers to take the full screen.
Is there an easy way to move the PageControl on top of my ViewControllers?
It could be the background of the parent view. I had a similar situation where the background color was actually the background of my parent control, not my own. Here is a tool I use that helped me narrow this down : http://www.sparkinspector.com. Here is another tool that does the same thing : http://revealapp.com.
Also one more thing - not sure if this would apply to your case, but it could be the background layer that might need its color set
CALayer *layer = self.layer;
[layer setBackgroundColor:[UIColor clearColor]];
if you set something to be clear color, the background color then depends on whatever is on the background, the view the page control is in (usually a uipagecontrol) has no background, and this is why you're seeing it as black.

clear color background nav bar, but still float above all the contents

I am a new iOS developer, i found some apps that can have a totally transparent nav bar, but still float above all the content, such as the app has a very nice background picture, and the nav bar is transparent, so you can see the entire background, but there is a scroll view on the navigation view controller. when scroll, it still goes under the nav bar.
when i try it, i set up my nav bar background as transparent like this
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];
but my scroll view will be totally visible when it goes under nav bar. I don't like that, does any one know how to make the nav bar transparent but still kind of floating on everything?
Thank you guys for the reputations, here is a screen shot from Yahoo weather their nav bar does exactly what i want.
But when i set the clear background to it, it becomes like this.
I am not 100% sure how Yahoo did it, but i can kind of fake that effect like this
I am inspired by BTGlassScrollView (https://github.com/BTLibrary/BTGlassScrollView) the approach i am using have several steps:
1.> set up your navigation controller like this:
Put your background image view first
Then add a wrapper view for your scroll view, and set the wrapper view background as Transparent (this wrapper view is very important, we have to fake the effect on this wrapper view)
drag your scroll view into the wrapper view, and set your scroll view background as Transparent as well.
2.> set up all the outlets for scroll view, wrapper view and background image view
3.> You might also want to hide the nav bar shadow image, here is the code, just in case if you need it
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
4.> Then paste this method into your class
- (CALayer *)createViewMaskWithSize:(CGSize)size startGradientAt:(CGFloat)start endGradientAt:(CGFloat)end
{
CAGradientLayer *mask = [CAGradientLayer layer];
mask.anchorPoint = CGPointZero;
mask.startPoint = CGPointMake(0.5f, 0.0f);
mask.endPoint = CGPointMake(0.5f, 1.0f);
mask.colors = #[(id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor whiteColor].CGColor];
mask.locations = #[#0.0, #(start/size.height), #(end/size.height), #1.0f];
mask.frame = CGRectMake(0, 0, size.width, size.height);
return mask;
}
The purpose for this method is to create a mask layer with a clear to white gradient on it.
5.> last step, simply add that to your wrapperView.layer.mask like this
// 64 in here is the position where the fade effect should start, and 80 is where the gradien should end
// you can change those 2 numbers and see different effects
self.scrollViewWrapperView.layer.mask = [self createViewMaskWithSize:self.scrollViewWrapperView.frame.size startGradientAt:64 endGradientAt:80];
The wrapper view is the key in this case, the nav bar won't work without it. and remember DO NOT put the background image view into the wrapper view, they should be on the same level, but background image under the wrapper view.
This is a very rough mock ups, but hope this gives you some ideas.

Using UIColor tiled images as the background of a view doesn't work with cornerRadius

I have used UIColor colorWithPatternImage to get a tiled color. I set this as the background of my view. After this, any changes to view.layer.cornerRadius do not have any affect: it doesn't change the corner radius. I have also tried adding another subview to my view, setting that's background color to the pattern and using cornerRadius on my view to no avail.
How can I fix this behaviour?
Thanks for your time.
Set the clipsToBounds of the view to YES and it should work. I had the same issue.
Here is my snippet:
self.leftPanelView.layer.cornerRadius = 10;
self.leftPanelView.clipsToBounds = YES;
self.leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"linePattern_gray.png"]];
which shows the linePattern_gray.png as the background patterned with a nice rounded corner.

Resources