I have white background and white label on it, so I need to give a shadow all side of characters I use this code and it works! but it cause to slowly scroll do you have any idea how can solve this problem?
cell.L_name.layer.shadowOpacity = 1.0;
cell.L_name.layer.shadowRadius = 1.0;
cell.L_name.layer.shadowColor = [UIColor blackColor].CGColor;
cell.L_name.layer.shadowOffset = CGSizeMake(1.0, 1.0);
try setting
cell.L_name.layer.shouldRasterize = YES;
this will render your label as a bitmap and might improve scrolling smoothness
additionally you could set
cell.opaque = YES;
which will optimize drawing performance as well.
Setting a shadowPath for the layer would probably increase the performance greatly.
cell.L_name.layer.shadowPath = [UIBezierPath pathWithRect:L_name.bounds].CGPath;
Besides, you can cache the generated shadow as a bitmap, which also increases the performance considerably. Do not forget to set rasterizationScale for retina displays.
cell.L_name.layer.shouldRasterize = YES;
cell.L_name.layer.rasterizationScale = [UIScreen mainScreen].scale;
Related
I have UITableView with 10 big images like Instagram and i have some blurview on that images. I add my visualeffects UITableViewCell like that;
_blurButtonEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
_visualButtonEffectView = [[UIVisualEffectView alloc] initWithEffect:_blurButtonEffect];
_visualButtonEffectView.layer.cornerRadius = 10.0f;
_visualEmojiEffectView = [[UIVisualEffectView alloc] initWithEffect:_blurButtonEffect];
_visualEmojiEffectView.layer.cornerRadius = 24.0f;
_visualButtonEffectView.layer.masksToBounds = YES;
_visualEmojiEffectView.layer.masksToBounds = YES;
_visualButtonEffectView.frame = CGRectMake(20.0f, _button.frame.origin.y + 7.0f, 48.0f, 48.0f);
_visualEmojiEffectView.frame = CGRectMake(_emoji.frame.origin.x - 4.0f, _button.frame.origin.y + 22.0f, ([UIScreen mainScreen].bounds.size.width/2) - 25.0f, 30.0f);
If button title is null, i show _visualEmojiEffectView and hide _visualButtonEffectView. Otherwise _visualButtonEffectView is always shown. While i'm scrolling my UITableView, performance is perfect but this blur effects shown so annoying, they seems like flashing with every scroll movement and touches. I can block this with this in cell;
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
If i'm rasterize my cell like that, blur effect works perfect but scrolling performance is awful even on iPhone 6. What is the correct way to configure UIBlurEffectView with UITableViewCell?
I know it is too late to reply but still i hope this helps someone. You can give a white background colour to the visual effect view with a very low alpha. Something like this:
[_visualButtonEffectView setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:0.2]];
You may also try using UIToolbar instead of a visual effect view. It does not give exactly the same effect but will still be good enough.
Hey I'm new to iPhone and I have been trying to set shadow for UIImageView using shadow gradient image i.e. "Image-Shadow.png" using below code.
imageView.layer.shadowColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:#"Image-Shadow.png"]].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.clipsToBounds = NO;
imageView.layer.shouldRasterize = YES;
My problem is, i am not getting shadow in my UIImageView using above code. Can you please tell me that is this the correct way to add shadow image in UIImageView or it is possible with some other way?
Problem is with the image. I don't think you can provide a pattern image to create a shadow!
Give a proper color like [UIColor blackColor].CGColor and it should work.
The problem is with this line:
imageView.layer.shadowOffset = CGSizeMake(0, 1);
where you are setting the shadow, but not giving it a visible space to display itself.
Positive or negative values should be given to both parameters.
Positive values stretch "down" and "to the right" of your view, negative values stretch "to the left" and "to the up" of your view.
here is my solution as per my requirement :
//set shadow gradient on image view
UIView *shadowView = [[UIView alloc] initWithFrame:imageView.frame]; //add view behind the image view
shadowView.layer.contents = (id) [UIImage imageNamed:#"Image-Shadow.png"].CGImage;
[imageView addSubview:shadowView];
Thanks to all.
I'm writing a UI for iPad and part of that UI needs progress bars for certain parts. However, I'm finding that configuring the UIProgressView is proving difficult. One of the requirements is that the endpoints of the progress view be square, however, I am unable to configure this via the layer's corner radius property:
fProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
fProgressView.layer.borderColor = [UIColor whiteColor].CGColor;
fProgressView.progress = 0.5f;
fProgressView.progressImage = nil;
fProgressView.trackImage = nil;
fProgressView.trackTintColor = self.fPatientListPanelColor;
fProgressView.progressTintColor = [UIColor whiteColor];
[fProgressView.layer setCornerRadius:1.0f];
[self.view addSubView:fProgressView]
I find I am also unable to control the height of it. Any thoughts on how to overcome these issues?
There is apparently no way to do this, so I ended up rolling my own version.
I use QuartzCore to set UILabel shadows in UITableViewCell:
cell.textLabel.layer.shadowColor = [[UIColor orange] CGColor];
cell.textLabel.layer.shadowOffset = CGSizeMake(0.0, 1.0);
cell.textLabel.layer.shadowRadius = 0.0;
cell.textLabel.layer.masksToBounds = NO;
But because of it slow performance, I have to implement -(void)drawRect:(CGRect)rect method.
Recently I found out that shadow for UILabel can be set with it properties:
cell.textLabel.shadowColor = [UIColor orangeColor];
cell.textLabel.shadowOffset = CGSizeMake(0.0, 1.0);
Now I want delete drawRect: implementation and just set shadows through properties.
QuartzCore CALayer shadowRadius default value is 3.0.
Though UILabel has not such property, is it mean that shadow radius equauls 0.0?
The documentation for UILabel says:
Text shadows are drawn with the specified offset and color and no blurring.
So, yes, the shadow radius is 0.
just a advise - setting shadow using QuartzCore in a UITableView cell impacts scroll performance. it would definitely not be smooth scrolling.
I suggest you use a UIImageView just below the UILabel to give the same effect. Its probably more work to keep the shadow-image updated with changes in design but if its a trade-off between reducing developer effort or improving user-experience; I would incline towards the latter 9 out of 10 times...
I can't find a solution for my issue, so I hope some experts could help me.
I have tableview with lots of cells. For each cell I have an image view with rounded corners:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *exampleView;
...
exampleView.layer.cornerRadius = 5.f;
exampleView.clipsToBounds = YES;
[cell.contentView addSubview:exampleView];
...
}
Resulting in a big lack of scrolling performance issue - when using cornerRadius and clipsToBounds = YES, any alternative solutions?
(The rounded corner image view contains pictures, and if the corner isn't set. The scrolling is smooth. So the problem is here)
EDIT #1: to clarify that I have already read other posts:
...
exampleView.frame = CGRectMake(5.0f,size.height-15.0f,30.0f,30.0f);
exampleView.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
exampleView.layer.cornerRadius = 5.0f;
exampleView.layer.borderWidth = 0.3f;
exampleView.layer.borderColor = [UIColor blackColor].CGColor;
exampleView.layer.masksToBounds = NO;
exampleView.layer.shouldRasterize = YES;
//exampleView.clipsToBounds = NO;
[exampleView setImage: myImage ];
EDIT #2:
It's like myImage is lapping over the rounded corner view. How do I make the image fit the rounded corner view correct? or am I missing something?
Just change the following line
exampleView.layer.masksToBounds = YES;
To round out the corners in your imageView. See images below.
The tableview scrolling is a issue with view compositing. In addition to suggestions above, this will certainly help -
Set the opaque property of the UITableViewCell's contentView property, and backgroundView property. Go:
[cell.contentView setOpaque:YES];
[cell.backgroundView setOpaque:YES];
This will help reduce the view compositing effort at the earliest possible stage.
There are additional, advanced, techniques which would require you to use asynchronous processing to process your images as you scroll. They may be overkill if the above techniques work.