UITableViewCell reorder control clips view in iOS 13 - ios

I put a background image in a UITableViewCell to make it more visually appealing. In iOS 13, the background image is clipped by the reorder control.
This did not happen with older versions of the OS.
The code is simple:
// Put a border around mBackgroundImage. Make it slightly smaller than the size of the cell so that the border doesn't run all the way to the edges.
cell.mBackgroundImage.frame = CGRectMake(2, 2, cell.frame.size.width-4, cell.frame.size.height-4);
cell.mBackgroundImage.layer.cornerRadius = 4;
cell.mBackgroundImage.layer.borderColor = [UIColor colorWithWhite:0.92 alpha:1.0].CGColor;
cell.mBackgroundImage.layer.borderWidth = 1;
cell.mBackgroundImage.layer.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.95 alpha:1.0].CGColor;
Any suggestions?

Problem solved by setting cell.contentView.clipsToBounds to NO. It looks like cell.contentView.clipsToBounds=YES had been ignored prior to iOS 13.

Related

Tableview: Add a shadow

My designer asked me to add a shadow to the cell of my tableview like this:
Currently I have implemented everything functional, even the Top | Latest header-view. How can I add such a shadow to the end of each tableviewsection?
Below is my solution. In this situation don't forget to set your view's backgroundColor even it's whiteColor and shadowOpacity.
And give an extra space around your cellSubView to show the shadow.
You can set appropriate values instead of mines depending on your requirements.
Hope this helps.
cellSubView.backgroundColor = [UIColor whiteColor];
cellSubView.layer.shadowColor = [UIColor blackColor].CGColor;
cellSubView.layer.shadowOpacity = 0.5;
cellSubView.layer.shadowOffset = CGSizeMake(0,10);
cellSubView.layer.shadowRadius = 3;

Set CALayer as SCNMaterial's diffuse contents

I've been searching all over the internet over the past couple of days to no avail. Unfortunately, the apple documentation about this specific issue is vague and no sample code is available (at least thats what I found out). What seems to be the issue you may ask...
I'm trying to set a uiview's layer as the contents of the material that is used to render an iPhone model's screen (Yep, trippy :P ). The iPhone's screen's UV mapping is set from 0 to 1 so that no issue persists in mapping the texture/layer onto the texels.
So, instead of getting this layer to appear rendered on the iPhone, same as left image, Instead, I get this rendered onto the iPhone like right image
Correct Render                                        Incorrect Render
Also note, that when I set a breakpoint and debug the actual iPhone node and view it in Xcode, a completely different render is shown and the layer gets half-fixed when I continue execution:
Now then... HOW do I fix this issue??? I've tried playing with the diffuse's contents transform matrix but nothing gets fixed. I've also tried resizing the UIView to 256x256 (since the UV seems to be 256x256 as shown in blender - the 3d modelling package), but that doesn't fix anything.
Here is the code for the layer:
UIView *screen = [[UIView alloc] initWithFrame:self.view.bounds];
screen.backgroundColor = [UIColor redColor];
UIView *temp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen.bounds.size.width, 60)];
temp.backgroundColor = [UIColor colorWithRed:0 green:(112.f/255.f) blue:(235.f/255.f) alpha:1];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(temp.bounds, 40, 0)];
label.frame = CGRectOffset(label.frame, 40, 0);
label.textColor = [UIColor colorWithRed:0 green:(48.f/255.f) blue:(84.f/255.f) alpha:1];
label.text = #"Select Track";
label.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:30];
label.minimumScaleFactor = 0.001;
label.adjustsFontSizeToFitWidth = YES;
label.lineBreakMode = NSLineBreakByClipping;
[temp addSubview:label];
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, temp.bounds.size.height - 2, temp.bounds.size.width, 2)];
separator.backgroundColor = [UIColor colorWithRed:0 green:(48.f/255.f) blue:(84.f/255.f) alpha:1];
[temp addSubview:separator];
[screen addSubview:temp];
screen.layer.contentsGravity = kCAGravityCenter;
Edit
What's even weirder is that if I capture a UIImage of the view using:
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
and use that as the diffuse's content... everything works out perfectly fine?! It's really weird and frustrating since the image's size is exactly the same as the uiview's...
Edit 2
I ended up just using an image of the view as the texture, which makes things much more static than I needed. I won't set this as the answer because I'll still be waiting for a correct fix to this issue even if it in a long time. So, if you have an answer and this topic has been opened for a long time, please bump it if you can. The documentation on this section is just so poor.
New post on an old thread, but this day-in-age, it's possible to set the UIView itself as SCNMaterialProperty (diffuse) contents. Intention to support this feature is communicated directly from SceneKit engineering at Apple, though the documentation has not yet been updated to reflect it.
To tied back to the original post, do not set a UIView.layer as material property contents; instead set contents to the UIView itself.
[Update: according to Lance's comment below, support for views may be getting worse rather than getting better.]
The SceneKit docs pretty strongly suggest that, while there are cases where you can use animated CALayers as material content, that doesn't include UIView layers:
SceneKit cannot use a layer that is already being displayed elsewhere (for example, the backing layer of a UIView object).
That suggests that if you want to make animated content for your material, you're better off with either Core Animation used entirely on its own or SpriteKit.

Style controls on iOS 6 with layers are wrong? (From iOS7)

I'm creating an app and I'm styling some controls like text fields and buttons with layers (for example changing the border color and thickness), or simply by changing the background color of the control from the Interface Builder.
On iOS 7 it's all working good, but when I run the application on iOS 6 (simulator) I see old style controls plus borders of the layer.
The two versions were running both with the iOS 6.1 SDK.
Here is the screen of what is happening: (I can't post images for the reputation on SO)
EDIT:
The code for the textfields i use is this:
UITextField* textField = (UITextField*) aView;
textField.layer.cornerRadius = 0.0;
textField.layer.borderColor = [[UIColor lightGrayColor] CGColor];
textField.layer.backgroundColor = [[UIColor whiteColor] CGColor];
And for the "Login" button i simply changed the background color in the IB.
In order to remove the border of the textFields, set the borderStyle to none:
textField.borderStyle = UITextBorderStyleNone;
As for the Login button, don't forget to set the button's type to Custom in IB.
Tell me if that works.

How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

It looks like this whenever off:
While I'd prefer more of a grey background. Do I really have to use a UIImageView?
Here is how I changed the fill color of my iOS7 UISwitch.
First you need to import QuartzCore.
#import <QuartzCore/QuartzCore.h>
Then set the background color and round the UISwitch's corners.
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor redColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
[self addSubview:mySwitch];
This will give you a UISwitch with a custom off (background) color.
Hope this helps someone:)
You can set the setOnTintColor property of your UISwitch to the color you desire.
You can also set this for the switch in Interface Builder. Just set the background colour of the UISwitch to whatever colour you want (white, in the example below), then set a User Defined Runtime Attribute of layer.cornerRadius = 16:
There's no API support for changing the off fill color of a UISwitch.
Adjusting the tintColor will only affect the outline, and adjusting the backgroundColor will affect the whole frame, including the parts outside the rounded bounds.
You either have to place a properly shaped opaque UIView behind it or - easier - use a custom open source implementation, such as MBSwitch, which allows you to set the off fill color.
You can also use an image as background, using the [UIColor colorWithPatternImage];
mySwitch.onTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"toggle-bg-on"]];
mySwitch.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"toggle-bg-off"]];
Adding to Barry Wyckoff solution : set tint color also
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor redColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
mySwitch.tintColor = [UIColor redColor];
[self addSubview:mySwitch];

Remove tint on TableView iOS 7

I am trying to remove the white view behind the alphabet indexer but have had no luck.
I am trying to make it clear but nothing has worked for me so far.
sectionIndexBackgroundColor is what your looking for. You can do something like this,
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
If you want to change the color of the highlighted state, use the following property.
tableView.sectionIndexTrackingBackgroundColor = [UIColor redColor];
Keep in mind that sectionIndexBackgroundColor became available in iOS7. So if your supporting iOS6 you might want to call something like this.
if ([tableView respondsToSelector:#selector(sectionIndexBackgroundColor)]) {
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
}

Resources