Change Everything to Black And White (Applying Blending to View Background Colour) - ios

Result:
The middle image with the alert box popup is the result I want to achieve.
When popup an alert box, everything changes to black and white. The way to achieve this in design is to adding a layer on top with background colour black and blending mode hue.
So in order to implement this, here is what I tried.
I tried to add a view on top (Transparent background). Inside that view, I draw a rectangle with blend mode hue.
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
UIColor.black.setFill()
context?.setBlendMode(.hue)
let rect = rect
context?.addRect(rect)
context?.drawPath(using: .fillStroke)
}
The UIView has constraint to set to full screen. However that just result a black rectangle.
Any hint on how to achieve this?

There is no such thing as a blend mode with what is behind the view. Blend mode is about drawing into this context.
To achieve what you're describing, you would have to take a snapshot of the current view controller's view and draw it in black-and-white into your context.
The usual thing, however, is just to set the tintAdjustmentMode. That is what a real alert view does.

Related

Is there a function to apply colors to masked corners of a view or button?

I need to know is there any function to fill the masked corners. I have tried CAShapelayer still, it is overlapping with the outside view. So, I need to fill it perfectly without showing the background color.
The below image shows the corners are occupied with pink color. But I need those colors to match with white.
Just apply the corner radius
view.layer.cornerRadius = 9.0
view.backgroundColor = UIColor.red.cgColor

uiscrollview zoom to overlay rect

I want to tap to zoom a UIImageView and put it inside a overlay.
Just like this picture.I want to put the cyan color rect to the blue one.How can I do this?
You can use multiple CALayers. CALayer can be overlaid easily, as you can stack sublayers

Working with transparency: View behind transparent view should only shine through and not overlap

I'm currently working with transparency and I'd like to have the following effect:
As you can see the line takes the full width of the view. There are some transparent UIViews also on this screen. The line seems to be below the transparent UIView and if it overlaps it has another color, because of the transparent UIView above. When there is no overlapping the line get its normal color.
How can I get this effect?
I tried to set the background of the UIView to transparent, but it didn't helped. The line has its normal color and doesn't interact with the transparency. Furthermore I tried to change the transparency of the view itself but with the same wrong result.
The rectangle above is done with code
UIView rectangle = new UIView (new CGRect (10, 10, 200, 120));
rectangle.BackgroundColor = UIColor.FromRGBA (204,115,225, 50);
UIView line = new UIView (new CGRect (0, 105, 320, 1));
line.BackgroundColor = UIColor.Red;
View.AddSubview (line);
View.AddSubview (rectangle);
line.SendSubviewToBack (rectangle);
the rectangle below is created in iOS designer.
Am I missing something?
Its all about the z order of the Subviews.
line.SendSubviewToBack (rectangle);
is probably not what you want.
If you add the line with its normal red color and add a UIView that has its alpha dropped to e.g. 0.5, then you should get the effect you want.
The z-order of the subviews was correct in my case. Depending on the color the effect I want is possible or not. So I made the following:
Choose another background color for the lavender color rectangles and adapt the alpha transparency to look similar. So something like this:
rectangle.BackgroundColor = UIColor.FromRGBA (245/255.0f,227/255.0f,249/255.0f,0.7f);

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).

iOS 7 SegmentControl Background Color

Picture says it all (see arrows). Any way I can make sure the background is transparent? If I set the background to transparent on the UISegmentedControl it sets the button color to transparent too, but we want to avoid this.
Clarification: We want to keep the buttons white, but get rid of the white stuff in the corners. Setting background to white does this but then makes the buton background transparent too, which we don't want.
Update: Now looks as follows, after trying Astri's suggestion and setting corner radius to 5. Still, there is a white space on the right.
After the clarification:
Try this:
yourSegmententControl.layer.cornerRadius = 5;
Make sure you import Quartz
I experienced the same white space on the right problem when I explicitly set the width of the UISegmentedControl.
To fix it, do not set the width of the segmented control – just set the width of each segment instead.
// Determine your segment width
CGFloat segmentWidth = 50.0;
// Loop through the segments
for (NSInteger i=0; i<mySegmentedControl.numberOfSegments; i++) {
// Set the width of each segment
[mySegmentedControl setWidth:segmentWidth forSegmentAtIndex:i];
}
The background colors of the views of the controlls are already transparent, so you need to set them too to whatever color you want, not just the background color of the view of the segmented controll. Keep in mind that the controlls have different configurations for their state.

Resources