I`ve a App like the iOS 10 Maps-App or maybe like the Home-Screen with Control Center. For example take a look at the Picture. If you open the Control Center the shadow of the background changes to black & transparent. How can i access this layer or subview and change the color from this shadow to another in my App. Maybe to red or white?
EDIT:
Maybe directly with the Framework.
https://github.com/iosphere/ISHPullUp
You can use UIVisualEffectView like this:
Obj-C:
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];//SELECT STYLE OF YOUR CHOICE
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;//view Will be YOUR_VIEW
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:blurEffectView];//This add Blur view to your view
Swift:
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(blurEffectView)
Sometimes open your eyes and you will find what you want. 😕 If you using the same Framework there is one variable you can change. In the sample of the Framework you can got to the "BottomVC" and add the following line to your viewDidLoad().
weak var pullUpController: ISHPullUpViewController!
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))
topView.addGestureRecognizer(tapGesture)
handleView.arrowSize = CGSize(width: 1 , height: 2)
//This line change the default 40% black to a 70% white.
pullUpController.dimmingColor = UIColor.white().withAlphaComponent(0.7)
}
The "Shadow" is just a normal View. Here you can see how the author has implemented this.
Related
I'm trying to reduce the quality of a message before its being sent, for example if the connect is poor I want to blur out the text in the UITextView and if connection improves or internet comes back, then remove the blur and show the normal text in the UITextView. I have tried using CATextLayer doesn't work. Is there a way I can achieve this?
cell.messageTextView.text = theText
let textLayer = CATextLayer()
textLayer.string = cell.messageTextView.text
textLayer.contentsScale = 0.2
cell.messageTextView.layer.addSublayer(textLayer)
You can drop the quality of the layer by making it rasterized and reducing the scale of it:
let badQualityRatio: CGFloat = 4
textView.layer.shouldRasterize = true
textView.layer.rasterizationScale = UIScreen.main.scale/badQualityRatio
Result:
you can set the rasterizationScale any number between 0 and UIScreen.main.scale
You could try something like this:
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = cell.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
cell.view.addSubview(blurEffectView)
Adding a UIVisualEffectView with blur effect on top of your table view cell.
I'd like to apply layer on top of ImageView that slightly blurrs it.
I put a view on top of imageView, subclass it as follows:
class BlurredView: UIView {
override func draw(_ rect: CGRect) {
self.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.backgroundColor = UIColor.clear
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(blurEffectView)
}
}
The result is quite different from what I expected.
How to customize it to make this blur much lighter, so the picture still shows some details?
As https://stackoverflow.com/users/1387306/chrstpsln mentioned in the comment, this can be achieved by changing the alpha of the UIVisualEffectView.
As a bonus, you can add a fade animation to make the transition feel smoother.
Heres an example of how you can add this effect to any viewController through an extension:
extension UIViewController {
func addBlurEffect() {
let blurEffect = UIBlurEffect(style: .light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = UIScreen.main.bounds
blurVisualEffectView.alpha = 0.1
// Bonus animation - Or just set the alpha higher
UIView.animate(withDuration: 0.3) {
blurVisualEffectView.alpha = 0.90
}
view.addSubview(blurVisualEffectView)
}
}
Usage:
let viewController = UIViewController()
viewController.addBlurEffect()
You can't change the blur amount, the only thing you can do is to change the blur effect style:
UIBlurEffectStyle.light
UIBlurEffectStyle.extraLight
UIBlurEffectStyle.dark
Try to change the blur effect alpha. Also, since your image is light, you should use the light style and not the extra light in order to not lose details.
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
blurEffect.alpha = 0.95
I have a view called componentsView that overlays mkmapview. I thought it would be cool to have this view transparent with a blur effect. So in my viewDidLoad method I typed:
let blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
blurView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
componentsView.insertSubview(blurView, atIndex: 0)
and that works, it blurs the map behind it. But the map is still colorful - is there a way of making it black and white? currently my panel has a clear color and I tried setting its tint color to black but that didn't work...
I am trying to create this effect.
Blur effect only on the scroll offset view
I tried to do this programmatically as follows
- (void)addBlurEffect {
// Add blur view
// CGRect statusBarViewRect = [[UIApplication sharedApplication] statusBarFrame];
CGRect bounds = self.bounds;
/*to extwnd from status bar till the end of navigation bar height*/
CGRect aRect = CGRectMake(0, self.frame.origin.y-40, self.frame.size.width, bounds.size.height+20);
/*Make a blur view*/
UIVisualEffectView *visualView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
/*Assign a tag to make it accessable from view hirarchy*/
visualView.tag = 10000;
visualView.frame = aRect;
visualView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:visualView];
self.backgroundColor = [UIColor colorWithRed:42.0f green:152.0f blue:231.0f alpha:0.7f];
[self sendSubviewToBack:visualView];
/*back button was disabled following enables it*/
visualView.userInteractionEnabled = false;
}
i am not able to recreate the UI. this is what i get
UIEffectView adds a gradient effect.
a gradient effect and not a clear view. how shall i recreate the required UI effect?
try this one :-
self.tableView.contentInset = UIEdgeInsetsMake(44,0,0,0);
Use this to add a blur effect to view.
var blurEffectView : UIVisualEffectView!
func addblurEffectToView()
{
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] // for supporting device rotation
blurEffectView.alpha = 1
view.addSubview(blurEffectView)
}
As you can see image below I want to create blur view with fade in edge effect. Does someone write me codes of how to implement this in ios?
Thanks
please take a look at this image - marked in red rectangle
let blurEffect = UIBlurEffect(style: .Light)
let imageView = UIImageView(image: UIImage(named:))//your ImageView
let visualEffectView = UIVisualEffectView(effect: blurEffect)
imageView.addSubview(visualEffectView)
You might need to change the frame of the visualEffectView to cover your image but this is the basics of it.