Make Google Maker like a Toggle Button - ios

Actually i am adding iconview to marker and change to another iconview when one tap on that marker. this can be easily done by adding iconview in didTapMarker delegate method. But How to change to default view when one select to another Marker. just like Toggle Button
- (void)viewDidLoad
{
for(int i=0;i<lat.count;i++)
{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[lat objectAtIndex:i]doubleValue],[[longit objectAtIndex:i]doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor colorWithRed:24.0/255.0 green:59.0/255.0 blue:91.0/255.0 alpha:1.0];
label.backgroundColor = [UIColor colorWithRed:177.0/255.0 green:177.0/255.0 blue:177.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:#"map2_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = _mapView;
}
}
and in didTapMarker delegate method
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:139.0/255.0 blue:58.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:#"map3_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
return YES;
}

You can userData property of GMSMarker for that, first set the userData with all your marker, so add this line inside your for loop of viewDidLoad where you are adding marker on Map.
marker.userData = #{#"isSelected":[NSNumber numberWithInt:0]};
Now on didTapMarker check like this
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:139.0/255.0 blue:58.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
NSNumber *number = [marker.userData objectForKey:#"isSelected"];
if ([number integerValue] == 0) {
[btn setImage:[UIImage imageNamed:#"map3_"] forState:UIControlStateNormal];
marker.userData = #{#"isSelected":[NSNumber numberWithInt:1]};
}
else {
[btn setImage:[UIImage imageNamed:#"map2_"] forState:UIControlStateNormal];
marker.userData = #{#"isSelected":[NSNumber numberWithInt:0]};
}
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
return YES;
}

Related

mulpitle UILabel in Navigation titleView [duplicate]

I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.
What i want is in following images
in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar.
There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.
Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.
So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..
you can add Multiple UIlabel or Image as look like bellow image:-
this can do using bellow code you can change Label and imageView frame and put as your requirement
- (void)viewDidLoad
{
UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = #"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = #"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:#"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];
self.navigationItem.titleView = btn;
}
You can add subviews directly to the navigationBar -
UINavigationBar *navBar = navController.navigationBar;
[navBar addSubview: yourLabel];
yourLabel frame origin will be relative to the navigation bar
Try this code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame: CGRectMake(160, 7 , 40, 30)];
[button0 setTitle:#"Sort" forState:UIControlStateNormal];
button0.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12];
[button0 setBackgroundImage:[UIImage imageNamed:#"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:#selector(sortAction) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
self.navigationItem.titleView = buttonContainer;
UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)];
lbl_title.text = str_HeaderTitle;
lbl_title.textColor = [UIColor whiteColor];
lbl_title.font = [UIFont fontWithName:#"Helvetica-Bold" size:16];
lbl_title.backgroundColor = [UIColor clearColor];
lbl_title.textAlignment = NSTextAlignmentCenter;
[buttonContainer addSubview:lbl_title];
You can set an arbitrary view instead of a view controller's title:
myViewController.navigationItem.titleView = someView;
Note that most likely the view's frame will be restricted to make room for leftBarButtonItem and rightBarButtonItem.
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)];
[label setBackgroundColor:[UIColor greenColor]];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)];
[imgView setBackgroundColor:[UIColor redColor]];
[[self.navigationController navigationBar] addSubview:label];
[self.navigationController.navigationBar addSubview:imgView];
Have a look at this piece of code. With some modifications it should solve your problem:
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:CGRectMake(15, 0, 57, 44)];
[imageButton setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
[titleLabel setText:#"some title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[self.navigationController.navigationBar addSubview:imageButton];
[self.navigationController.navigationBar addSubview:titleLabel];
Just modify the values in the CGRectMake() to fit your needs.

Customize the UIButton resize according to text length and place UILabel after that

I have used following code and got error as below i.e less space in small text and more space long text
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
UIButton *BtnBreadcrumb = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BtnBreadcrumb addTarget:self action:#selector(selectBtnBreadcrumb:)
forControlEvents:UIControlEventTouchUpInside];
[BtnBreadcrumb setTitle:selectedDepartment forState:UIControlStateNormal];
BtnBreadcrumb.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
BtnBreadcrumb.tintColor=ThemeColor;
CGSize stringsize = [selectedDepartment sizeWithAttributes:#{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]}];
BtnBreadcrumb.frame = CGRectMake(10, 5, stringsize.width, 40);
[view addSubview:BtnBreadcrumb];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(stringsize.width, 5, 200, 40)];
//[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string = [NSString stringWithFormat:#"/ %#",selectedCategory];
label.font = [UIFont fontWithName:#"Helvetica" size:15.0];
label.textColor = TextColor;
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:0.933f green:0.933f blue:0.933f alpha:1.00f]];
return view;
}
I have study following links
iOS: UIButton resize according to text length
How can i increase the button width dynamically depends on the text size in iphone?
Replacement for deprecated -sizeWithFont:constrainedToSize:lineBreakMode: in iOS 7?
Replacement for deprecated sizeWithFont: in iOS 7?
IOS 7 sizeWithFont Deprecated
Please use:
CGSize size1 = [strkeyword1Partner1 sizeWithAttributes:#{NSFontAttributeName:[UIFont fontWithName:FONT_MYriad_REGULAR size:14.0f]}];
// Values are fractional -- you should take the ceilf to get equivalent values
CGSize adjustedSize1= CGSizeMake(ceilf(size1.width), ceilf(size1.height));
[btnKewword1 setFrame:CGRectMake(self.view.frame.size.width-(adjustedSize1.width +14), btnKewword.frame.origin.y, adjustedSize1.width+5, 20)];
Try this
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(50, 100, 100, 0);
btn.titleLabel.numberOfLines = 0;
[btn setTitle:#"dsgdfgdfsdsfgdfsgdfsgdfsgdfgdfgfkdsfgdsgdksfgkdskgf" forState:UIControlStateNormal];
[self.view addSubview:btn];
Please try following code I add the size of the UIButton.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
UIButton *BtnBreadcrumb = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BtnBreadcrumb addTarget:self action:#selector(selectBtnBreadcrumb:)
forControlEvents:UIControlEventTouchUpInside];
[BtnBreadcrumb.titleLabel setFont: [BtnBreadcrumb.titleLabel.font fontWithSize:17]];
[BtnBreadcrumb setTitle:#"Test" forState:UIControlStateNormal];
BtnBreadcrumb.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
BtnBreadcrumb.tintColor=ThemeColor;
CGSize stringsize = [selectedDepartment sizeWithAttributes:#{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]}];
BtnBreadcrumb.frame = CGRectMake(10, 5, stringsize.width, 40);
[view addSubview:BtnBreadcrumb];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(stringsize.width, 5, 200, 40)];
//[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string = [NSString stringWithFormat:#"/ %#",selectedCategory];
label.font = [UIFont fontWithName:#"Helvetica" size:15.0];
label.textColor = TextColor;
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:0.933f green:0.933f blue:0.933f alpha:1.00f]];
return view;
}

UIButton is not working on didSelectAnnotationView

Hi I have custom view in didSelectAnnotationView when user tap on the pin maker I'm displaying the custom view with UILabel and a UIButton everything is working fine but the UIButton is not clickable please tell how to resolve this issue.
My code.
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view1
{
NSString *bult;
if ([view1.annotation isKindOfClass:[MapPin class]]) {
MapPin *annot = view1.annotation;
NSLog(#"tit%#",annot.nsname);
bult=annot.nsname;
}
myview = [[UIView alloc]initWithFrame:CGRectMake(-60, -110, 200, 100)];
myview.layer.cornerRadius = 10;
myview.backgroundColor = [UIColor yellowColor];
myview.userInteractionEnabled = YES;
[view1 addSubview:test];
buldingname = [[UILabel alloc] initWithFrame:CGRectMake(5, -15, 150, 80)];
buldingname.text=bult;
[buldingname setTextColor:[UIColor blackColor]];
[buldingname setBackgroundColor:[UIColor clearColor]];
[buldingname setFont:[UIFont fontWithName: #"Trebuchet MS" size: 14.0f]];
buldingname.lineBreakMode = NSLineBreakByWordWrapping;
buldingname.numberOfLines = 3;
[myview addSubview:buldingname];
moredetail=[UIButton buttonWithType:UIButtonTypeRoundedRect];
moredetail.frame= CGRectMake(0, 55, 200, 50);
[moredetail setTitle:#"Click here for more details" forState:UIControlStateNormal];
[moredetail addTarget:self action:#selector(nextbtn:) forControlEvents:UIControlEventTouchUpInside];
[moredetail setExclusiveTouch:YES];
[myview addSubview:moredetail];
}
My calling method.
- (IBAction)nextbtn:(id)sender
{
NSLog(#"click");
}
I have used the above code its not working please tell me where I'm doing wrong how to resolve this issue.
Thanks in Advance.
It is not working because the mapView still handles the touch event.
Just add an DetailView in the:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
static NSString *reuseIdentifier = #"Your_identifier";
MKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
if (view == nil)
{
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
view.image = [UIImage imageNamed:#"your_annotaion_image.png"];
}
view.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
view.rightCalloutAccessoryView = rightButton;
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"your_icon_image"]];
view.leftCalloutAccessoryView = icon;
return view;
}
and then you can call:
-(void)showDetails:(UIButton*)button
{
//do your stuff here
}
there is absolutely no need to build a annotation callout view yourself, just change the design of the default one.
You need to be add sub view to your custom view then its work.
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view1
{
NSString *bult;
if ([view1.annotation isKindOfClass:[MapPin class]]) {
MapPin *annot = view1.annotation;
NSLog(#"tit%#",annot.nsname);
bult=annot.nsname;
}
myview = [[UIView alloc]initWithFrame:CGRectMake(-60, -110, 200, 100)];
myview.layer.cornerRadius = 10;
myview.backgroundColor = [UIColor yellowColor];
myview.userInteractionEnabled = YES;
[view1 addSubview:myview];
buldingname = [[UILabel alloc] initWithFrame:CGRectMake(5, -15, 150, 80)];
buldingname.text=bult;
[buldingname setTextColor:[UIColor blackColor]];
[buldingname setBackgroundColor:[UIColor clearColor]];
[buldingname setFont:[UIFont fontWithName: #"Trebuchet MS" size: 14.0f]];
buldingname.lineBreakMode = NSLineBreakByWordWrapping;
buldingname.numberOfLines = 3;
[myview addSubview:buldingname];
moredetail=[UIButton buttonWithType:UIButtonTypeRoundedRect];
moredetail.frame= CGRectMake(0, 55, 200, 50);
[moredetail setTitle:#"Click here for more details" forState:UIControlStateNormal];
[moredetail addTarget:self action:#selector(nextbtn:) forControlEvents:UIControlEventTouchUpInside];
[moredetail setExclusiveTouch:YES];
[myview addSubview:moredetail];
}
check this code

IOS, setting up Gesture Tap on UILabel thats inside a UIScrollView

I have a UIScrollView and inside this Scroll View i have some controls. Specifically a label thats underlined and i have setup Tap Gesture for the UILabel but doesn't seem to fire the methods that the Tap Gesture is bound to.
Here is the code:
-(void)setupUserNameControls:(UIScrollView*)scroll{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 23, 70, 16)];
label.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
label.text = #"First Name";
label.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:label];
UIView *textView = [[UIView alloc] initWithFrame:CGRectMake(88, 16, 215, 28)];
textView.backgroundColor = [UIColor colorWithRed:60.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
[scroll addSubview:textView];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 55, 70, 16)];
label2.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
label2.text = #"Last Name";
label2.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:label2];
UIView *textView2 = [[UIView alloc] initWithFrame:CGRectMake(88, 48, 215, 28)];
textView2.backgroundColor = [UIColor colorWithRed:60.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
[scroll addSubview:textView2];
UIImageView *imageViewSep = [[UIImageView alloc] initWithFrame:CGRectMake(10, 92, 300, 2)];
UIImage *imageSep = [UIImage imageNamed:#"seperator.png"];
imageViewSep.image = imageSep;
[scroll addSubview:imageViewSep];
UIView *viewImage = [[UIView alloc] initWithFrame:CGRectMake(10, 108, 58, 58)];
viewImage.backgroundColor = [UIColor colorWithRed:132.0f/255 green:132.0f/255 blue:132.0f/255 alpha:1.0f];
[scroll addSubview:viewImage];
UIImageView *imageViewUser = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 48, 48)];
UIImage *imageUser = [UIImage imageNamed:#"defaultuser.jpg"];
imageViewUser.image = imageUser;
[viewImage addSubview:imageViewUser];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:#"Click to select your user image"];
[attributeString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:1]
range:(NSRange){0,[attributeString length]}];
UILabel *labelPickImage = [[UILabel alloc] initWithFrame:CGRectMake(88, 126, 215, 16)];
labelPickImage.numberOfLines = 0;
labelPickImage.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
labelPickImage.attributedText = attributeString;
labelPickImage.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:labelPickImage];
UITapGestureRecognizer *userImageTextTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(userImageSelectTap:)];
[userImageTextTap setNumberOfTouchesRequired:1];
[userImageTextTap setNumberOfTapsRequired:1];
[labelPickImage addGestureRecognizer:userImageTextTap];
}
-(void)userImageSelectTap:(UIGestureRecognizer *)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) Picker {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
This is how i set up the UIScrollView and pass it in:
UIScrollView *userInfoScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 108, screenRect.size.width, screenRect.size.height - 40 - viewTop.bounds.size.height - viewTopBorder.bounds.size.height)];
[userInfoScrollView setBackgroundColor:[UIColor colorWithRed:228.0f/255 green:228.0f/255 blue:228.0f/255 alpha:1.0f]];
userInfoScrollView.userInteractionEnabled = YES;
[self.viewUser addSubview:userInfoScrollView];
make sure the label stays in front of the scrollView.
[scroll bringSubviewToFront:labelPickImage];
Also,
labelPickImage.userInteractionEnabled = YES;

iOS iCarousel image offset

Good afternoon. ICarusel I use in my application. I have an image that is loaded as image view. Images are placed exactly in the center. Please tell me how do I move the image up to only 50 pixels in it without moving the rest of the content?
The method for creating views like that:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
NSString *docDir = [NSHomeDirectory() stringByAppendingPathComponent:#"Library/Caches"];
NSDictionary *myDic =[magazinesInfo objectAtIndex:index];
//Resize image
UIImage *img = [UIImage imageWithImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/%#_img.png",docDir,[myDic objectForKey:#"title"]]] scaledToSize:CGSizeMake(375,510)];
UIImageView *romb = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 118, 135)];
UIImageView *faceImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1004)];
UIImage *dwImage = [UIImage imageNamed:#"button.png"];
UIImage *readImage = [UIImage imageNamed:#"read_button.png"];
UIImage *deleteImage = [UIImage imageNamed:#"delete_button.png"];
if(view ==nil)
{
UIButton *myDownloadButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[myDownloadButton setBackgroundColor:[UIColor blackColor]];
[myDownloadButton setHidden:YES];
romb.image = [UIImage imageNamed:#"romb.png"];
view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1004)];
[view setBackgroundColor:[UIColor blackColor]];
view = faceImage;
faceImage.image = nil;
((UIImageView *)view).image = nil;
view.contentMode = UIViewContentModeCenter;
//Magazine number
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(345, 85, 75, 29)];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textAlignment = NSTextAlignmentCenter;
[myLabel setFont:[UIFont fontWithName:#"OpenSans-Light" size:36.0f]];
myLabel.textColor = [UIColor whiteColor];
myLabel.tag = 1;
//Magazine name
nameMag = [[UILabel alloc] initWithFrame:CGRectMake(-65, 450, 100, 100)];
nameMag.backgroundColor = [UIColor yellowColor];
nameMag.textAlignment = NSTextAlignmentCenter;
[nameMag setFont:[UIFont fontWithName:#"OpenSans-Light" size:30.0f]];
nameMag.textColor = [UIColor blackColor];
nameMag.tag = 3;
//Date
dateMag = [[UILabel alloc] initWithFrame:CGRectMake(-67, 500, 500, 30)];
dateMag.backgroundColor = [UIColor greenColor];
dateMag.textAlignment = NSTextAlignmentCenter;
[dateMag setFont:[UIFont fontWithName:#"OpenSans-Light" size:20.0f]];
dateMag.textColor = [UIColor blackColor];
dateMag.tag = 4;
//Download button
downloadButton = [[UIButton alloc] initWithFrame:CGRectMake(350, 700, 128, 37)];
[downloadButton setBackgroundImage:dwImage forState:UIControlStateNormal];
[downloadButton addTarget:self action:#selector(pressDownload:) forControlEvents:UIControlEventTouchUpInside];
downloadButton.tag = 5;
//Read button
readButton = [[UIButton alloc] initWithFrame:CGRectMake(250, 750, 128, 37)];
[readButton setBackgroundImage:readImage forState:UIControlStateNormal];
[readButton addTarget:self action:#selector(readMag:) forControlEvents:UIControlEventTouchUpInside];
readButton.hidden=YES;
readButton.tag = 8;
//Delete button
deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(400, 750, 128, 37)];
[deleteButton setBackgroundImage:deleteImage forState:UIControlStateNormal];
[deleteButton addTarget:self action:#selector(deleteMag:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.hidden=YES;
deleteButton.tag = 9;
//Progress bar
downloadProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(100, 800, 127, 8)];
downloadPrecent = [[UILabel alloc]initWithFrame:CGRectMake(300, 800, 8, 8)];
downloadPrecent.backgroundColor = [UIColor blueColor];
[downloadPrecent setFont:[UIFont fontWithName:#"OpenSans-Light" size:20.0f]];
dateMag.textColor = [UIColor blackColor];
downloadProgress.tag = 6;
downloadPrecent.tag = 7;
downloadProgress.hidden = YES;
downloadPrecent.hidden = YES;
//Add image subview
[view addSubview:romb];
//Label subview
[view addSubview:myLabel];
[view addSubview:nameMag];
[view addSubview:dateMag];
//Progressbar subview
[view addSubview:downloadProgress];
[view addSubview:downloadPrecent];
//Buttons subview
[view addSubview:downloadButton];
[view addSubview:readButton];
[view addSubview:deleteButton];
[view addSubview:myDownloadButton];
}
else
{
romb.image = (UIImage*)[romb viewWithTag:3];
((UIImageView *)faceImage).image = (UIImage*)[view viewWithTag:2];
myLabel = (UILabel *)[view viewWithTag:1];
nameMag = (UILabel *)[view viewWithTag:3];
dateMag = (UILabel *)[view viewWithTag:4];
downloadProgress = (UIProgressView *) [view viewWithTag:6];
downloadPrecent = (UILabel *)[view viewWithTag:7];
downloadButton = (UIButton *) [view viewWithTag:5];
readButton = (UIButton *) [view viewWithTag:8];
deleteButton = (UIButton*) [view viewWithTag:9];
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(#"index is: %i",index);
NSLog(#"current item index %i",[self.carousel currentItemIndex]);
NSLog(#"%hhd",[fileManager fileExistsAtPath:[NSString stringWithFormat:#"%#/%#_mag.pdf",docDir,[myDic objectForKey:#"title"]]]);
if ([fileManager fileExistsAtPath:[NSString stringWithFormat:#"%#/%#_mag.pdf",docDir,[myDic objectForKey:#"title"]]] == YES && (index == [self.carousel currentItemIndex]))
{
NSLog(#"%#",[[view subviews] objectAtIndex:9]);
[[[view subviews] objectAtIndex:9] setHidden:NO];
readButton.hidden = NO;
deleteButton.hidden = NO;
downloadButton.hidden = YES;
}
else
{
[[[view subviews] objectAtIndex:9] setHidden:YES];
readButton.hidden = YES;
deleteButton.hidden = YES;
downloadButton.hidden = NO;
}
((UIImageView *)view).image = img;
myLabel.text = [myDic objectForKey:#"title"];
dateMag.text = [myDic objectForKey:#"date"];
romb.image = [UIImage imageNamed:#"romb.png"];
return view;
}
Now it looks like this (do not worry, it's still developing :))
http://files.mail.ru/B2B41BA915624173B646184D4283D9F9?t=1
Use the contentOffset property to shift the carousel contents relative to the carousel view without changing their perspective.
You can use the viewpointOffset propert instead if you want it to look like the perspective has changed (i.e as if you are looking at the carousel from below).

Resources