Why setClipsToBounds:NO disables setCornerRadius: for UItableview? - ios

I'm creating UIItableview. For the first cell I want to have a user Image with a button to allow him to change the image. (not so complicated).
Somehow I have a strange problem: When I set setMasksToBounds:NO the [self.userTable.layer setCornerRadius:20.0]; is simply get disabled.
I am attaching a code with output example:
//Initiate UserTable
//[self.userTable setClipsToBounds:NO];//from the documentation this line is set by default
[self.userTable.layer setCornerRadius:20.0];
[self.view addSubview:self.userTable];
later in cellForRowAtIndexPath: I add:
[myCellView.contentView addSubview:photo]; //My photo is UImageview
If I uncomment the line [self.userTable setClipsToBounds:NO] I get:
but my corners are not rounded any more......
I read the following questions
this and this and still cant figure that out?
Did someone had this problem and can provide a fix which will not force me to change all my code? and also how the 2 options are related to each other?
Thanks a lot.

Calling setCornerRadius applies a mask to your CALayer, which is then used to mask the bounds and create the rounded corner effect.
By calling setMasksToBounds:NO, you are disabling the mechanism used to round the corners.
In short, you can't have it both ways.
Consider making that row in the tableview taller, or using a custom view instead of a standard UITableViewCell.

Related

Adding button gradient before appearing in iOS

I want to use gradient for a button in iOS, but since the button's frame (button.layer.bounds) changes because of Auto Layout, I found that I have to put the insertSublayer in the viewDidAppear method -- which means the button first appears without the gradient and then gets repainted with it. Is there anyway to get the final button size in viewWillAppear so that I can apply the correct size gradient before it appears?
Here's how I do it now:
- (void)viewDidAppear:(BOOL)animated{
CAGradientLayer *gradient1=[CAGradientLayer layer];
gradient1.colors=[NSArray arrayWithObjects:(id)light.CGColor,(id)dark.CGColor,nil];
gradient1.cornerRadius=10;
gradient1.frame=_go_button.layer.bounds;
gradient1.borderColor=dark.CGColor;
gradient1.borderWidth=1;
[_go_button.layer insertSublayer:gradient1 atIndex:0];
Sometimes by asking a question leads you to finding your own answer.... Here's a link to a website I found that answered it: has the solution
The simple answer is to put the gradient code into viewDidLayoutSubviews instead of viewDidAppear.

Swift - ios - creating ballon buttons

I want to create a set of buttons that will look like this:
(The selected buttons are those with a different background)
Any ideas for a simple implementation?
Are there any known open source implementations for this?
Thanks!
Following is the library which may be use to solve your problem,
For different appearance you need to give the conditional code for that but with out that your problem may solve with this library or code.
You can download the sample code of RRTagController project here.
For rounded corners use UIButton.layer.cornerRadius. if you set corner radius to half of the box you will get circle. For the border color use layer.borderColor = UIColor.redColor().CGColor.
For the background color of the button you can keep track with selected state of the button. Here is an example of using selected state: UIButton state selected
Next thing you could do is to keep data about selected ones, since the best way to do something like this would be UITableView - seems like every row of buttons have same height, and if you want to send that somewhere you can keep track about what items are selected.
I think the best way is to use UICollectionView.

How to implement Circular iCarosel?

I tried all the ways by setting the respective value's but i'm unable
get below one by using iCaurosel,or is there any controller which gives same functionality
? can you help me?
You should choose iCarousel type to wheel:
self.carousel.type = iCarouselTypeWheel;
but if you mean items margin, this is not possible:
https://github.com/nicklockwood/iCarousel/issues/306
Please check following sample. this is dynamic circles (views) you can add.:)
https://github.com/mpospese/CircleLayout
Happy coding.
You can achieve the same functionality by creating the custom circular UICollectionView layout.Please visit the following link to solve this.
http://developer.xamarin.com/guides/ios/user_interface/introduction_to_collection_views/
You can do this using carousel.type = iCarouselTypeWheel and then using the carousel:valueForOption:withDefault: delegate method to adjust circle radius, number of items shown, etc.
To position the circle off-center like that, use carousel.contentOffset.
You may find that the gesture handling is a bit weird though, because the pan gesture will still be linear even though the view appears circular.

Add icon to SBSearchTableViewCell

I am trying to add an icon to a SBSearchTableViewCell.
I was adding a subview on top of the cell but that still left a border, and the text was underneath the icon.
http://i.imgur.com/tGqWaEa.png
I tried hooking into -[SBSearchModel _imageForDomain:andDisplayID:] but the domain is 0 and the displayID is (null).
Code: http://pastebin.ca/2460380
Resources:
http://theiostream.tumblr.com/post/54339870761/hacking-the-ios-spotlight-v2
https://github.com/theiostream/SearchLoader
Did you try to set image using -(void)setTitleImage:(id)image animated:(BOOL)animated; method (I'm not sure what it does, but that is the only method to set image in the cell you are using...)? And, How about just creating your own labels, and place them on the right places? That should not be that hard, I think. Good Luck!
EDIT
Sorry it seems like the method I mentioned is available only on iOS 7 and higher. I suggest you to use you own UILabels and UIImageView with imitation to the original.
ANOTHER EDIT
It looks like the SBSearchTableViewCell is the subclass of the UITableViewCell, so why don't you use the it's imageView property to set the image (or, icon) to the cell?
You can move the border over by setting cell.sectionHeaderWidth. Then you can add a subview like you already have done.

What exactly IS the highlighted image in a UIImageView?

This question boggles my mind and I cannot find an answer. I looked all over the documentation, tried out code, and searched Google, but I can't find anything. The UIImageView in iOS programming can have an image set to it, but you can also set a highlighted image to it. What exactly is this highlighted image?
you can set two different images to an UIImageView, one to its image property, another to its highlightedImage property.
There are many cases where you want to change the state of the image (eg: a checkmark) from off to on or vice versa. in that case, instead of you setting the UIImageView's image to the appropriate one everytime, you can just say
theCheckMarkImageView.image = regularImage;//set the regular image
theCheckMarkImageView.highLightedImage = highlightedImage;
(based on your logic show it highlighted or not).
theCheckMarkImageView.highlighted = YES/NO;
In addition to all this, do check Ethan Huang's answer about how tabelviewcell works with this property. Quite useful if you are showing different images based on cell selection.
highlightedImage use for highlight ImageView,simple.
imageView.highlightedImage = [UIImage imageNamed:#"hightlighted.png"];
imageView.highlighted = YES;
Don't need to waste time to search or read a lot. Objective-C is meaningful language. Just drag ImageView and make a try code, step by step test all property, method in UIImageView.h(in UIKit framework) and you'll understand.
Do the same with other UI element.
Besides Nitin Alabur's answer, a useful tip here:
UITableViewCell or UICollectionViewCell has a .selected property. If you put an UIImageView in a cell, then, when you select the cell, the imageView will use the .highlightedImage instead of .image.
Thus you can make cell selection visual state easily.
The highlighted image is for when you have a control that has a UIImageView that can be pressed. While the user is pressing the control, the highlighted image is shown. When the control is not being pressed, the normal image is shown.
All commenters have been wrong or answered the wrong question or been too wordy. Here's the simple and correct answer:
The highlighted image state is when the user's finger is touching the imageview.

Resources