Blur back Images in ICarousel - ios

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

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);
}

How to change Button image added to UITableview section header in ios

Here is my code
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"Add_plus_iCon_iphone_4s"] forState:UIControlStateNormal];
button.frame = CGRectMake(sectionView.frame.size.width-10, 10, 20, 20);
[button addTarget:self action:#selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:button];
}
- (void)btnAction:(UIButton *)sender
{
int i = [sender.titleLabel.text intValue];
NSNumber *numb;
if(i == 0)
{
numb = [NSNumber numberWithBool:NO];
sender.titleLabel.text = #"1";
[sender setImage:[UIImage imageNamed:#"Add_minus_iCon_iphone_4s"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:#"Add_plus_iCon_iphone_4s"] forState:UIControlStateHighlighted];
}
else
{
numb = [NSNumber numberWithBool:YES];
sender.titleLabel.text = #"0";
[sender setImage:[UIImage imageNamed:#"Add_plus_iCon_iphone_4s"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:#"Add_minus_iCon_iphone_4s"] forState:UIControlStateHighlighted];
}
}
First thing set images of button for both state (UIControlStateNormal, UIControlStateSelected) in ViewDidLoad and then do [cell.btnSelect setSelected:YES]; or [cell.btnSelect setSelected:NO]; as per requirement.
Otherwise change image for UIControlStateNormal when button tapped.
you are creating UIButton each time header load, which cause your button to reset,
1 way is to design cell in storyborad or xib and use reference,
Also have a DataSource to keep track of values
e.g.
if([dataSouce containsObject:yourItem]){
//selected button image
[cell.btnSelect setSelected:YES];
}
else{
//unselected button image
[cell.btnSelect setSelected:NO];
}

How to make segmented control like this

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).

How to change button image added to TableView section header

I've added a button to section header which shows a view on clicking it. My need is that I've to show an "Up-arrow" image while view is shown and "Down-arrow" image when view is hidden.
How can I achieve this? Please help me ...
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 316, 60)];
[btn setTag:section];
[aView addSubview:btn];
[btn addTarget:self action:#selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
btn.backgroundColor=[UIColor clearColor];
}
I will suggest that you can have 2 images - 1 for 'Up' and 1 for 'Down' arrow.
Set default image to the btn for state UIControlStateNormal and set the other image for state UIControlStateSelected.
Now in your sectionTapped: method just change the state of the button.
So when you show or hide your view you need to set the button selected YES/NO.
Hope this helps.
I had done this before in one of my app.
Take this code as Reference
1.Specific Method.
- (void)methodName:(UIButton *)sender
{
int i = [sender.titleLabel.text intValue];
NSNumber *numb;
if(i == 0)
{
numb = [NSNumber numberWithBool:NO];
sender.titleLabel.text = #"1";
[sender setImage:[UIImage imageNamed:#"down.png"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:#"up.png"] forState:UIControlStateHighlighted];
}
else
{
numb = [NSNumber numberWithBool:YES];
sender.titleLabel.text = #"0";
[sender setImage:[UIImage imageNamed:#"up.png"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:#"down.png"] forState:UIControlStateHighlighted];
}
}
2.Setting UIButton Programatically in UITabelview viewForHeaderInSection.
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(240, 20, 30, 30)];
[button addTarget:self
action:#selector(methodName:)
forControlEvents:UIControlEventTouchDown];
button.tag = section;
if([[sectionsArray objectAtIndex:section] boolValue])
{
[button setImage:[UIImage imageNamed:#"up.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"down.png"] forState:UIControlStateHighlighted];
button.titleLabel.text = #"0";
}
else
{
[button setImage:[UIImage imageNamed:#"down.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"up.png"] forState:UIControlStateHighlighted];
button.titleLabel.text = #"1";
}
You can trying using BOOL to check if the button has been pressed or not and animate to rotate the image in your button to point up or down.
-(IBAction)dropdownBtnClicked:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
if (!isDropdownEnabled)
{
//BOOL - checking if the button has been pressed or not
isDropdownEnabled=TRUE;
drpDwnBtn.transform=CGAffineTransformMakeRotation(270/180*M_PI);
}
else
{
isDropdownEnabled=FALSE;
drpDwnBtn.transform=CGAffineTransformMakeRotation(0);
}
[UIView commitAnimations];
}

Resources