How to make segmented control like this - ios

Today I'm creating a custom segmented control. The appearance of the control as follow:
I tried two methods:
- (void)setBackgroundImage:(UIImage *)backgroundImage
forState:(UIControlState)state
barMetrics:(UIBarMetrics)barMetrics
- (void)setDividerImage:(UIImage *)dividerImage
forLeftSegmentState:(UIControlState)leftState
rightSegmentState:(UIControlState)rightState
barMetrics:(UIBarMetrics)barMetrics
However, here is the result I got:
I extracted the border image and the divider line (vertical line) from the design, but the result looks bad. Please help me if you have any idea.

I have always found it too much work to customize the UISegmentedControl and it is not really fully customizable.
I suggest you create yourself a custom UIView inheriting 3 buttons. They are fully customizable and fully controllable:
#define BASE_TAG 123
NSArray *titles = [NSArray arrayWithObjects:#"MAP", #"LOCATIONS", #"BUS", nil];
double y = 0.0;
double x = 0.0;
double width = (frame.size.width / [titles count]);
double height = frame.size.height;
for (int i = 0; i < [titles count]; i++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(x, y, width, height)];
[button.titleLabel setTextAlignment:NSTextAlignmentCenter];
[button setBackgroundColor:[UIColor clearColor]];
[button setTag:(BASE_TAG + ([titles count] - i - 1))];
[button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[_buttons addObject:button];
x += width;
}
This is your button action. Here the button clicked will be selected and all others unselected:
- (void)buttonAction:(id)sender
{
UIButton *button = (UIButton *)sender;
NSInteger index = 0;
for (UIButton *btn in self.subviews)
{
if (btn == button)
{
index = (btn.tag - BASE_TAG);
[btn setBackgroundColor:[UIColor colorFromHexString:#"#5ac8f5" alpha:1.0]];
[btn setSelected:YES];
}
else
{
[btn setBackgroundColor:[UIColor clearColor]];
[btn setSelected:NO];
}
}
/* Trigger a delegate here if you like
if ([_delegate respondsToSelector:#selector(didSelectedIndex:)])
{
[_delegate didSelectedIndex:index];
}
*/
}
This lets you pre set a selected index:
- (void)setSelectedIndex:(NSInteger)index
{
for (UIButton *button in self.subviews)
{
if (button.tag == (BASE_TAG + index))
{
[button setBackgroundColor:[UIColor colorFromHexString:#"#5ac8f5" alpha:1.0]];
[button setSelected:YES];
}
else
{
[button setBackgroundColor:[UIColor clearColor]];
[button setSelected:NO];
}
}
}
This is just a suggestion code I pulled from an old project. You will have to customize it for your needs.

Here is a very good article how to do custom segmented control.
Looks like you have tried similar approach but you have messed up something with images (probably you misunderstand the API so this article should do the job for you).

Related

UIbutton does not reset to default after click on Reset button

I have a product filter list and I would like to reset all data to default (without click) after clicked on Reset button.
But now my case is after I clicked on Reset button, selected items will not reset accordingly and it will change to other items. You may refer to screenshot as below:-
Here is my part of related code, please help and thanks for your advice:-
FilterItemCell.m
- (void)setUpUI
{
_contentButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_contentButton setTitleColor: ThemeBlueColor
forState:UIControlStateNormal];
[_contentButton addTarget:self action:#selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_contentButton];
}
- (void)checkButtonTapped:(id)sender
{
if ([sender isSelected]) {
!_attributeItemClick ? : _attributeItemClick();
[sender setSelected: NO];
[_contentButton setImage:nil forState:0];
[_contentButton setTitleColor:ThemeBlueColor forState:UIControlStateNormal];
} else {
!_attributeItemClick ? : _attributeItemClick();
[sender setSelected: YES];
[_contentButton setImage:[UIImage imageNamed:#"isSelectYes"] forState:0];
[_contentButton setTitleColor:ThemeRedColor forState:UIControlStateNormal];
}
}
Filter_ViewController.m
- (void)setUpBottomButton
{
CGFloat buttonW = FiltrateViewScreenW/2;
CGFloat buttonH = 40;
CGFloat buttonY = ScreenH -10 - buttonH;
NSArray *titles = #[#"Reset",#"OK"];
for (NSInteger i = 0; i < titles.count; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:titles[i] forState:UIControlStateNormal];
button.tag = i;
CGFloat buttonX = i*buttonW;
button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
button.titleLabel.font = PFR16Font;
if (i == 0)
{
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:#"Button2-1"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(bottomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
else if (i == 1)
{
[button setBackgroundImage:[UIImage imageNamed:#"Button1-1"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(bottomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
}
[_filtrateConView addSubview:button];
}
}
- (void)bottomButtonClick:(UIButton *)button
{
if (button.tag == 0) //Reset Button
{
//CURRENT CODE TO RELOAD COLLECTION VIEW DATA
[self.collectionView reloadData];
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FilterItemCellID forIndexPath:indexPath];
cell.attribute_name=[[self.filterItem[indexPath.section] valueForKey:#"attribute_name"]objectAtIndex:indexPath.row];
return cell;
}
for reset function you need to renew all the data as in starting like you might be storing the ticked ones in an array.
you need to refresh the array you are using to display in your collectionView.
Then you need to call reload on your collectionView.
In your function I can see only reload function call not any function for refreshing the data in the array you might be using to display in the collection view.
I hope this helps you. Do let me know in case you need anything else.

getting element from array one by one and createbutton

I have a UItextFeild as search bar on clicking a tableview with suggestion open.now i want to click on that row and make a button with its label in below view as described in image .how can i acheive this
I want it one by one means when i click on row it create a button on view and UITableView hide then again i start searching and on again clicking on some other row make a button with different value of X.
_selectednames = [NSMutableArray arrayWithCapacity:self.sortedArray.count];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// MGContactItemsModel *model = _arrayForContacts[indexPath.row];
self.searchText.text = [NSString stringWithFormat:#"%#",[_sortedArray objectAtIndex:indexPath.row]];
self.tableView.hidden = YES;
[_selectednames addObject:_searchText.text];
for (int i; i < _selectednames.count ; i++) {
[self makeLabelsAndButtons:i];
}
now in my makeLabelsAndButtons funtion i done something like this
CGFloat xOffset = 10.0f;
int buttonCount = 0;
CGRect buttonFrame = CGRectMake(xOffset, 10.0, 50.0, 15.0);
NSString *nameString = [self.selectednames objectAtIndex:indexPath];
UIButton *_button = [UIButton buttonWithType:UIButtonTypeCustom];
[_button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
//_button.frame = CGRectMake(xOffset, 10.0, 50.0, 15.0);
for(int i=buttonCount; i >0;i++) {
xOffset = xOffset+10;
buttonFrame.origin.x += buttonFrame.size.width+xOffset;
}
_button.frame = buttonFrame;
buttonCount++;
_button.tag = indexPath;
//button.center = CGPointMake(xOffset, 10.0f);
//[button setBackgroundImage:[UIImage imageNamed:picString] forState: UIControlStateNormal];
[_button setTitle:self.selectednames[indexPath] forState:UIControlStateNormal];
_button.backgroundColor = [UIColor lightGrayColor];
_button.titleLabel.font = [UIFont fontWithName:#"Arial" size:8.0f];
_button.layer.cornerRadius = 10.0f;
_button.layer.masksToBounds = YES;
[self.buttonView addSubview:_button];
NSLog(#"name: %#", nameString);
also on clicking button it will removed.any help would be thankful.
It works for me.Please try it.
y=20;
x=20;
for (int i=0; i<[arrAssignUsers count]; i++) {
CGRect screenRect=[[UIScreen mainScreen]bounds];
CGFloat screenWidth=screenRect.size.width;
[arrBtnStatus addObject:[NSNumber numberWithBool:NO]];
NSString *strNames=[arrAssignUsers objectAtIndex:i];
stringsize=[strNames sizeWithAttributes:
#{NSFontAttributeName: [UIFont systemFontOfSize:20.0f]}];
btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
CGFloat m=x+stringsize.width+10;
CGFloat n=screenWidth-20;
if (m<=n) {
btn.frame=CGRectMake(x, y,stringsize.width,stringsize.height);
x=x+stringsize.width +10;
}
else
{
y=y+stringsize.height+10;
x=20;
btn.frame=CGRectMake(x, y,stringsize.width,stringsize.height);
x=x+stringsize.width+10;
}
[btn setTitle:self.arrAssignUsers[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn.tag=i;
[btn addTarget:self
action:#selector(notifyButtonPressedInEditTask:) forControlEvents:UIControlEventTouchUpInside];
btn.backgroundColor=WHITE_COLOR;
btn.layer.cornerRadius=10;
[btn.layer setMasksToBounds:YES];
btn.layer.borderWidth=2.0f;
btn.layer.borderColor=[UIColor orangeColor].CGColor;
[self checkNotifybtnStatus:btn];
[cell addSubview:btn];
}
}
It may helps to you.Thank you
You can use UICollectionView to create buttons. All you need to do is
1. Create custom cell with button as you want
2. When you tap on table view cell, add item to array and reload UICollectionView
3. Show buttons and it will automatically add scrollview for you.
When you tap on UICollectionView cell, remove object from array and reload UICollectionView again.
This will more easy as compared to adding buttons and setting frames.
And design UICollectionView cell in such way that it will same length as your text, use NSLayoutConstraints for it. It will work fast and smooth.
Code will be minimum and reusable.
Try out this working code...
Take UIScrollView in your Xib for buttons
//Adding menu buttons
btnArray = #[#"SYMPTOMATIC", #"SOCIAL", #"VOCATIONAL", #"PERSONAL"];
[self addButtonsInScrollMenu:btnArray];
/**
* Add Menu Buttons in Menu Scroll View
*
* #param buttonArray Array containing all menu button title
*/
#pragma mark - Add Menu Buttons in Menu Scroll View
-(void) addButtonsInScrollMenu:(NSArray *)buttonArray
{
CGFloat buttonHeight = self.menuScrollView.frame.size.height;
CGFloat cWidth = 0.0f;
for (int i = 0 ; i<buttonArray.count; i++)
{
NSString *tagTitle = [buttonArray objectAtIndex:i];
CGFloat buttonWidth = [self widthForMenuTitle:tagTitle buttonEdgeInsets:kDefaultEdgeInsets];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(cWidth, 0.0f, buttonWidth, buttonHeight);
[button setTitle:tagTitle forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:#"Roboto-Regular" size:12.0f];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[self.menuScrollView addSubview:button];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, button.frame.size.height - kButtonBorderHeight, button.frame.size.width, kButtonBorderHeight)];
bottomView.backgroundColor = [UIColor darkTextColor];
bottomView.tag = 1001;
[button addSubview:bottomView];
if (i == 0)
{
button.selected = YES;
[bottomView setHidden:NO];
}
else
{
[bottomView setHidden:YES];
}
cWidth += buttonWidth;
}
NSLog(#"scroll menu width->%f",cWidth);
self.menuScrollView.contentSize = CGSizeMake(cWidth, self.menuScrollView.frame.size.height);
}

Select/Deselect for dynamically created UIButtons

I will explain the Scenario:
I am dynamically creating three UIButtons inside a for loop.The condition is by default the first button should be bordered.Now if we select other buttons the previous button's border should go and now the border should be present for selected button.
for (int btnsCount = 0 ; btnsCount <[DataList count]; btnsCount++) {
self.graphSubDataButton = [[UIButton alloc] init];
self.graphSubDataButton.frame = CGRectMake(buttonsOffset, 0, 120, 40);
[self.graphSubDataButton setTitleColor:UIColorFromRGB(0x548DCD) forState:UIControlStateNormal];
[self.graphSubDataButton.titleLabel setFont:[UIFont fontWithName:AVENIR_NEXT_MEDIUM size:13.0f]];
self.graphSubDataButton.tag = btnsCount+1;
[self.graphSubDataButton addTarget:self action:#selector(enableRespectiveButton2:) forControlEvents:UIControlEventTouchUpInside];
buttonsOffset = buttonsOffset+30 + self.graphSubDataButton.frame.size.width ;
if (self.graphSubDataButton.tag==1)
{
[self.graphSubDataButton.layer setBorderWidth:1.2f];
[self.graphSubDataButton.layer setBorderColor:[UIColorFromRGB(0x3070BA) CGColor]];
[self.graphSubDataButton.layer setCornerRadius:8.0f];
}
}
-(void) enableRespectiveButton2:(UIButton *) sender
{
}
I have changed your code structure little to make it work properly, you can comment if you don't understand something.
NSInteger defaultSelectedTag = 1;
for (int btnsCount = 0 ; btnsCount <[DataList count]; btnsCount++) {
UIButton *graphSubDataButton = [UIButton buttonWithType:UIButtonTypeCustom];
graphSubDataButton.frame = CGRectMake(buttonsOffset, 0, 120, 40);
[graphSubDataButton setTitleColor:UIColorFromRGB(0x548DCD) forState:UIControlStateNormal];
[graphSubDataButton.titleLabel setFont:[UIFont fontWithName:AVENIR_NEXT_MEDIUM size:13.0f]];
graphSubDataButton.tag = btnsCount+1;
[graphSubDataButton addTarget:self action:#selector(enableRespectiveButton:) forControlEvents:UIControlEventTouchUpInside];
buttonsOffset = buttonsOffset+30 + self.graphSubDataButton.frame.size.width ;
//add your button somewhere
//e.g.
//[self.view addSubview:graphSubDataButton];
if (graphSubDataButton.tag == defaultSelectedTag) {
[self setBorderForButton:graphSubDataButton];
}
}
- (void) setBorderForButton:(UIButton *)sender {
[sender.layer setBorderWidth:1.2f];
[sender.layer setBorderColor:[UIColorFromRGB(0x3070BA) CGColor]];
[sender.layer setCornerRadius:8.0f];
}
- (void) enableRespectiveButton2:(UIButton *) sender {
for(UIButton *buttons in [sender.superview subviews]) {
if([buttons isKindOfClass:[UIButton class]]) {
if(![buttons isEqual:sender]) {
//add logic to, remove borders
//buttons.layer.borderWidth = 0.0f;
}
}
}
[self setBorderForButton:sender];
}
Use tag to get current selected button or much simple: iterate through all subviews and set border to 0 for UIButtons
for (UIView *subview in [uiv_ButtonsView subviews]) {
if([subview isKindOfClass:[UIButton class]]) {
subview.layer setBorderWidth:0.0f;
}
}
then use:
UIButton *button=(UIButton *)sender;
[button.layer setBorderWidth:1.2f];
[button.layer setBorderColor:[UIColorFromRGB(0x3070BA) CGColor]];
[button.layer setCornerRadius:8.0f];
Create dynamic buttons like :
int buttonsOffset = 50;
for (int btnsCount = 0 ; btnsCount <3; btnsCount++)
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor blueColor];
btn.frame = CGRectMake(buttonsOffset, 100, 120, 40);
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
btn.tag = btnsCount+1;
[btn addTarget:self action:#selector(enableRespectiveButton2:) forControlEvents:UIControlEventTouchUpInside];
buttonsOffset = buttonsOffset+30 + btn.frame.size.width;
if (btn.tag==1)
{
[btn.layer setBorderWidth:1.2f];
[btn.layer setBorderColor:[UIColor greenColor].CGColor];
[btn.layer setCornerRadius:8.0f];
self.graphSubDataButton = btn;
}
[self.view addSubview:btn];
}
And click event of button is as following
- (void)enableRespectiveButton2:(UIButton *)sender
{
sender.selected = TRUE;
[sender.layer setBorderWidth:1.2f];
[sender.layer setBorderColor:[UIColor greenColor].CGColor];
[sender.layer setCornerRadius:8.0f];
self.graphSubDataButton.selected = FALSE;
[self.graphSubDataButton.layer setBorderWidth:0.0f];
[self.graphSubDataButton.layer setBorderColor:[UIColor clearColor].CGColor];
[self.graphSubDataButton.layer setCornerRadius:0.0f];
self.graphSubDataButton = sender;
}
Create dynamic buttons with for loop as shown below.
for(int i = 0 ;i <3; i++) {
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
NSString * title = [NSString stringWithFormat:#"Button %d",i];
[btn setTitle:title forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:#"BorderImg"] forState:UIControlStateSelected];
[btn setBackgroundImage:[UIImage imageNamed:#"UnBordered"] forState:UIControlStateNormal];
if(i == 0) [btn setSelected:YES];
else [btn setSelected:NO];
[btn setTag:i];
[btn addTarget:self action:#selector(btnTapped:) forControlEvents:UIControlEventTouchUpInside];
}
Have 2 images
Highlighted border (BorderImg)
Normal border (UnBordered)
Set those images to button while creating in for loop
- (void)btnTapped:(UIButton *) btn {
if(! btn.isSelected) {
[btn setSelected:YES];
}
Inside button selector method, based on the sender selection state , update the button selected state. (In side selector method i.e btnTapped set other buttons selected state to false)

Blur back Images in ICarousel

I am using iCarouselTypeCoverFlow library in my app. I want to blur the back images.
I am able to blur images in viewForItemAtIndex. but while scrolling i am not able to update. here is my code for viewForItemAtindex
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
image = [items objectAtIndex:index];
button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
button.tag=index;
//NSLog(#"%d %d",carousel.currentItemIndex,index);
if (selectedindex == index) {
[button setBackgroundImage:[items objectAtIndex:index] forState:UIControlStateNormal];
}
else {
[button setBackgroundImage:[self blurredImageWithImage:[items objectAtIndex:index]] forState:UIControlStateNormal];
}
return button;
}
and here is my didscroll
- (void)carouselDidScroll:(iCarousel *)carousel
{
NSInteger current = (carousel.currentItemIndex);
// NSLog(#"%d", current);
NSInteger nextIndex = (carousel.currentItemIndex + 1) % carousel.numberOfItems;
// NSLog(#"%d", nextIndex);
NSInteger prevIndex = (carousel.currentItemIndex + carousel.numberOfItems - 1) % carousel.numberOfItems;
// NSLog(#"%d", prevIndex);
}
Any suggestion or help would be appreciated.
So finally i got my answer. definitely not hoping for this . but unfortunately answer is ,
nicklockwood answer

Programmatically Click 10 UIButtons one after another in UIScrollView

I am developing one control where 10 UIButtons are added in UIScrollView. Now I have a requirement to click every Button one after another after some delay. can you all guide me how to do that?
here is the code what I have done.
in viewcontroller.h file
#property (weak) IBOutlet UIScrollView *mapScrollView;
#property (strong) UIButton *addContactIcon;
in viewcontroller.m file
// Set up ScrollView with UIButtons
NSUInteger xPosition = 1;
NSUInteger countIndex = 0;
for (ContactModule *sortedContacts in _distanceList) {
_addContactIcon = [[UIButton alloc] initWithFrame:CGRectMake(xPosition, 7, 30, 30)];
_addContactIcon.tag = countIndex;
[_addContactIcon addTarget:self action:#selector(mapsScrollButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
_addContactIcon.layer.cornerRadius = 2.0;
_addContactIcon.clipsToBounds = YES;
[_addContactIcon setBackgroundImage:[UIImage imageWithContentsOfFile:dataPath] forState:UIControlStateNormal];
[_addContactIcon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_mapScrollView addSubview:_addContactIcon];
xPosition += _addContactIcon.frame.size.width + 2;
countIndex = countIndex + 1;
}
_mapScrollView.contentSize = CGSizeMake(30 * _distanceList.count + 34, 40);
[_mapScrollView setShowsHorizontalScrollIndicator:NO];
Here is the Button Click Method For Every Button:
- (void)mapsScrollButtonClicked:(UIButton *)clickButton {
// Set Annotation Callout
[_mapsView selectAnnotation:[_mapsView.annotations objectAtIndex:clickButton.tag] animated:YES];
}
Now the requirement is I want to call Action Method for Every UIButtons in UIScrollview. for that I am doing something wrong below. help me with that:
for(NSUInteger count=0; count<[_distanceList count];count++) {
[UIView animateWithDuration:0.4
delay:0.8
options:0
animations:^{
[_addContactIcon sendActionsForControlEvents:UIControlEventTouchUpInside];
} completion:nil];
}
Hi you could do soemthing like below to click all the UIButtons on your view.
UIButton *button;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *buttonMaster;
buttonMaster = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonMaster addTarget:self
action:#selector(masterButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[buttonMaster setTitle:#"Show View" forState:UIControlStateNormal];
buttonMaster.frame = CGRectMake(80.0, y, 160.0, 40.0);
buttonMaster.tag = 100;
[self.view addSubview:buttonMaster];
y = 60;
for (int x=0; x<=10; x++)
{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(button1:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, y, 160.0, 30.0);
button.tag = x;
//[paintView addSubview:button];
[self.view addSubview:button];
y = y + 70;
}
[buttonMaster sendActionsForControlEvents:UIControlEventTouchUpInside];
if ([[self.view viewWithTag:0] isKindOfClass:[UIButton class]]) {
//UIButton *button = (UIButton *) view;
// do something funky with button
UIButton *myBtns = (UIButton *)[self.view viewWithTag:0];
NSLog(#" button tapped is %ld", myBtns.tag);
[myBtns sendActionsForControlEvents:UIControlEventTouchUpInside];
[myBtns setBackgroundColor:[UIColor greenColor]];
} else {
// do something funky with view
NSLog(#"do nothing ");
}
}
- (void)listSubviewsOfView:(UIView *)view {
// Get the subviews of the view
NSArray *subviews = [view subviews];
// Return if there are no subviews
//if ([subviews count] == 0) return; // COUNT CHECK LINE
for (UIView *subview in subviews) {
UIButton *myBtns = (UIButton *)[self.view viewWithTag:subview.tag];
//UIButton *myBtns = (UIButton *)[self.view viewWithTag:0];
if(myBtns.tag == 100 ){
NSLog(#"Master Button tag :- Dont do anything ");
}else
{
//[myBtns sendActionsForControlEvents:UIControlEventTouchUpInside];
NSLog(#"tags are %ld ", myBtns.tag);
}
// List the subviews of subview
//[self listSubviewsOfView:subview];
}
}
-(void) clickAllButtons{
for (int i = 0; i<=10; i++) {
UIButton *myBtns = (UIButton *)[self.view viewWithTag:i];
[myBtns sendActionsForControlEvents:UIControlEventTouchUpInside];
}
}
- (IBAction)masterButtonTapped:(UIButton*)sender{
//[self listSubviewsOfView:self.view];
// [self clickAllButtons];
}
- (IBAction)button1:(UIButton*)sender{
NSLog(#"test");
//NSLog(#"Button clicked %ld", tag);
}

Resources