I have a UICollectionViewCell in a UICollectionView containing two components
1 x UIImageView
1 x UIView
The UIView would ideally contain a couple of labels, and has the following properties set as default:
backgroundColor = .clear
isHidden = true
The UICollectionView has clipsToBounds set to false.
In the delegate of the UICollectionView, I am using the didUpdateFocusIn function to determine which cell will receive focus next, and un-hide the UIView.
As the UIImageView has the adjustsImageWhenAncestorFocused set to true, there is a drop-shadow drawn by tvOS when it automatically applies the zoom + parallex effect.
As can be see in the two pictures below (the second picture has the UIView's backgroundColor set to .black for clarity), the shadow is clipped by the empty space belonging to the UIView in the cell beside it, even though the UIView is already hidden.
Is there some way that I can resolve this?
Edit: Have added a third image which shows the shadow behaving perfectly when the UIView is totally removed from the .xib.
Well, it turns out that I'm a bumbling fool.
I forgot that I had set the bottom constraint of the UIImageView to be anchored to the top of the UIView that was below it.
The net result of hiding the UIView caused the UIImageView to seek out the bottom of the UICollectionViewCell, and that caused the clipping issues.
I have now constrained the UIImageView to a fixed height, and the problem has been resolved!
Since tvOS 11, there is no need to bind your view constraints to the UIImageView constraints to get that effect.
You can get that effect making use of the new property overlayContentView of UIImageView.
Link to the documentation:
https://developer.apple.com/documentation/uikit/uiimageview/2882128-overlaycontentview
A more elaborated explanation can be found from the minute 15:00 of the following WWDC video:
https://developer.apple.com/videos/play/wwdc2017/209/
If the method offered by Apple to get this effect, is not enough for your specific case, I also recommend this great third party library which basically allows getting a Parallax effect in any UIView.
https://github.com/PGSSoft/ParallaxView
Related
I have a UILabel centered within a UIView that expands/contracts depending on the device screen size. I've applied constraints so that the UILabel remains centered no matter the UIView size, which works fine.
Now I'm finding myself resizing the UIView manually like so (where mainView is the View Controller):
self.myView.frame = CGRectMake(0,0,self.mainView.frame.width, self.mainView.frame.height)
So this stretches the UIView to fill the whole screen/View Controller (it's also animated). I assumed the UILabel would continue to centre itself automatically, but it seems to pin itself as though it were constrained to the top of the UIView, leaving a lot of empty myView space below it.
How can I tell the UILabel to remain in the centre of the height-changing UIView that it's in?
We need to see your constraints to help, but:
You need to use centering constraints.
Set the bounds, not the frame of myView.
You might need to call setNeedsLayout on the view of the ViewController you are in
Also, set the background color of the UILabel -- it could be centered, but the text is not centered inside of it. For that, set the alignment properties.
I am working in an app in which I need to give feature like Notes App in iphone. as shown in first screen shot , initially , notes leaves a tab before the content starts, I also wanted to do the same and for that when I set Left Content inset (of UITextView) by 25 , it shows like in screenshot 2, here you may see the image also gets shifted. I have set image as background. I don't know how to solve this problem.
I also tried by adding image as subview of UITextview but it won't repeat the lines, while scrolling (image of lines) like notes app.
I'm setting the background of Textview by following code.
[textView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"line_image.png"]]];
Please tell me if I am going wrong or any extra effort needed to get desired output.
Thanks
UITextView is UIScrollView subclass so all relevant delegate method are available for you (e.g. scrollViewDidScroll:) - you can adjust your custom background in that method.
There's very nice post on Dr.Touch blog about recreating Notes app interface - you can get general idea about how it is done from it. Basically what is done there is adding custom view that draws background behind the text view and adjust it in text view's delegate methods and also using KVO on its 'contentSize' property.
#Dinesh gave nice solution but it doesn't sound to be generic as I want to use image of lines instead of drawing them. Image has some special effects that can not be achieved by drawing. So to solve it I created a table view below the textview keeping textview's background transparent. Now just added the image of line to my tableview's custom cell and set content offset of UItableview same as of the scrollview (subview of text view ,refering to the answer of #Vladimir ) .
And used the following code to scroll my tableview with scrolling the textview and got the desired output.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
tableView.contentOffset =scrollView.contentOffset;
}
Keeping my tableview's number of rows at a very large number.
PS: instead of setting the content inset of textview, i set its frame's X position and decreased the width relaively.
I am using an AQGridView to display my data in a grid on iPad. Every cell is a UIView subclass and typically, there are 18 cells displayed simultaneously.
I would like to add a round corner to these cells, so I set the cornerRadius property of the relevant layers (i.e. the layer of the main UIView and of one subview). However, this results in performance issues and the scrolling is not smooth any more. When using other CALayer properties, such as shadowOpacity, this does not happen.
Are there any other ways to add a rounded corner (apart from using an image)? Or am I doing something wrong?
I also saw a major performance hit when using cornerRadius on the layer of a view that contained a UIImageView subview. Rasterization solved that problem: view.layer.shouldRasterize = YES;
It could be where you're placing the setCornerRadius call. Make sure it's somewhere that only gets called once, not, for example, in a drawRect method.
Does anyone know of any reason why indentation of a UITableViewCell would center the cell's UIImageView horizontally? In theory (and judging by the screenshots and apps I've seen in the past), the imageView should always align to the right, keeping a consistent space to the two labels. In my case (screenshot below), it doesn't. This is a default UITableViewCell with the UITableViewCellStyleSubtitlestyle. Any clues? I've been looking at this for quite a while and can't seem to figure it out.
Update: apparently UITableViewCellStyleDefault doesn't have this issue - imageView's are right-aligned with the (single) label. Why there is a difference between the two styles is beyond me.
(green/blue areas added to illustrate the issue)
How UITableViewCell draws its contentView is not how you would normally draw subviews in an UIView. It does not modify frame property of imageView, textLabel and detailLabel. I guess it gets those views graphic references and dealing with custom drawing.
Which means, there is no control. Unfortunately I also have to say you need some customizations. But it would be enough just to have a custom content view, not to subclass the whole table view cell class.
I am currently working on an application for a client, and they have made an odd request. The request involves putting a custom image as the indicator for the scrollview. I am not even sure if this is possible but if it is can you please let me know how one would go about doing that.
Thanks
UIScrollView streches a small, semi-transparent circle image to generate its scrollbars. You can find this image as the first subview of a UIScrollView:
UIImageView *circle = [scrollView.subviews objectAtIndex:0];
However, as I said this image is stretched, and as far as I can tell, only the alpha values are considered when drawing the scroll bars.
So for example if you're only interested in changing the top/bottom ends of the scroll bar, you can try to change this image. However, I doubt you'll be able to do anything interesting.
A possible solution that comes to mind, and this is only a theory, is to add a custom, transparent UIView on top of a UIScrollView. Then you can hide the default scroll bar (by using showsHorizontalScrollIndicator and showsVerticalScrollIndicator), pass the necessary touch events to the UIScrollView to scroll the content, and draw the scrollbars in your custom view.