My code right now for didSelectItemAtIndexPath is the following:
- (void)collectionView:(AFIndexedCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if(collectionView.index == 0){
NSLog(#"Reordenador contenido por columna %li",indexPath.item);
self.my_data = [self.my_data sortByColumn:indexPath.item skip:1 areAllNumbers:TRUE];
[self.tableView reloadData];
}else{
//show a new window with the content of the cell in a Text Field
NSLog(#"Row = %li; Column = %li - content = %#",collectionView.index,indexPath.item,[self.my_data objectInRow:collectionView.index column:indexPath.item]);
}
}
my_data = custom 2D array class object
How would I programmatically open a new popup window / new view with the content of the selected cell inside, for example, a Text Field, and 2 buttons - Save / Cancel?
Fixed with the following coding:
UIView *mySubView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
[mySubView setBackgroundColor:[UIColor blackColor]];
mySubView.tag = TFIELDSUBVIEW_TAG;
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(2, 10, 300, 80)];
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.font = [UIFont systemFontOfSize:12];
self.textField.placeholder = [self.the_matrix objectInRow:collectionView.index column:indexPath.item];
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.textField.textAlignment = NSTextAlignmentCenter;
self.textFieldColumn = indexPath.item;
self.textFieldRow = collectionView.index;
UIButton *buttonOK = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOK.tag = TFIELDSUBVIEW_TAG;
[buttonOK setBackgroundImage:[UIImage imageNamed:#"ok.jpg"] forState:UIControlStateNormal];
[buttonOK addTarget:self
action:#selector(okClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonOK setTitle:#"" forState:UIControlStateNormal];
buttonOK.backgroundColor = [UIColor grayColor];
buttonOK.frame = CGRectMake(50, 100, 50, 30);
buttonOK.tintColor = [UIColor greenColor];
UIButton *buttonCANCEL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonCANCEL.tag = TFIELDSUBVIEW_TAG;
[buttonCANCEL addTarget:self
action:#selector(cancelClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonCANCEL setBackgroundImage:[UIImage imageNamed:#"cancel.jpg"] forState:UIControlStateNormal];
[buttonCANCEL setTitle:#"" forState:UIControlStateNormal];
buttonCANCEL.backgroundColor = [UIColor grayColor];
buttonCANCEL.frame = CGRectMake(120, 100, 75, 30);
buttonCANCEL.tintColor = [UIColor redColor];
[mySubView addSubview:buttonOK];
[mySubView addSubview:buttonCANCEL];
[mySubView addSubview:self.textField];
[self setCustomView:mySubView];
[self.view reloadInputViews];
setCustomView being the following:
-(void) setCustomView:(UIView *)customView {
NSUInteger z = NSNotFound;
if (_customView) {
z = [self.view.subviews indexOfObject:_customView];
}
if (z == NSNotFound) {
[self.view addSubview:customView];
} else {
UIView *superview = _customView.superview;
[_customView removeFromSuperview];
[superview insertSubview:customView atIndex:z];
}
_customView = customView;
}
Related
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setBackgroundImage:xxx] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
}
it works perfect on iOS14.
but on iOS15, XCode13 beta, it doesn't work anymore.
OC:
if (#available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance configureWithOpaqueBackground];
appearance.backgroundColor = [UIColor whiteColor];
appearance.shadowColor = [UIColor whiteColor];
appearance.shadowImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
}
Swift:
if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
appearance.shadowColor = .white
appearance.shadowImage = UIImage.color(.white)
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
}
just use this code, the background image can work in iOS 15
if (#available(iOS 13.0, *)) {
UINavigationBarAppearance *navigationBarAppearance = [UINavigationBarAppearance new];
[navigationBarAppearance configureWithOpaqueBackground];
[navigationBarAppearance setBackgroundImage:image];
self.navigationController.navigationBar.scrollEdgeAppearance = navigationBarAppearance;
self.navigationController.navigationBar.standardAppearance = navigationBarAppearance;
}
swift:
if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundImage = image
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
}else{
self.navigationController?.navigationBar.setBackgroundImage(image, for: .default)
}
I has the same issue and here is my code:
if (#available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance configureWithOpaqueBackground];
//appearance.backgroundColor = [UIColor blueColor];
appearance.shadowColor = [UIColor whiteColor];
appearance.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:24.0/255.0 green:44.0/255.0 blue:122.0/255.0 alpha:1.0f], NSForegroundColorAttributeName,[UIFont fontWithName:#"AvenirNext-Demibold" size:21], NSFontAttributeName,nil];
appearance.backgroundImage = [UIImage imageNamed:#"Bg_portrait_540x120_1.png"];
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
}
1) My annotation shows the title and subtitle of not.
I have already tried a lot, but I can not.
2) If an annotation has been selected, the annotation will be centered in the middle of the window. So the map is moved. Any idea?
3) My Callout button does not work anymore, I've got the # selector (openAnything) but I want to use this function is triggered - (void) mapView: (MKMapView *) mapView annotationView: (MKAnnotationView *) view calloutAccessoryControlTapped: (UIControl *) control {
Enough to ask, here's a video and some source code
http://www.youtube.com/watch?v=Ur1aqeYEFHw&feature=youtube_gdata_player
Thanks
TAPPMapViewControler.m
- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[TAPPMapAnnotation class]])
{
static NSString *shopAnnotationIdentifier = #"Filiale";
//pinView = (MKPinAnnotationView *)
TAPPMapAnnotationCustom* pinView = (TAPPMapAnnotationCustom*)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:shopAnnotationIdentifier];
[self.myMapView dequeueReusableAnnotationViewWithIdentifier:shopAnnotationIdentifier];
if (pinView == nil)
{
// if an existing pin view was not available, create one
TAPPMapAnnotationCustom *customPinView = [[TAPPMapAnnotationCustom alloc] initWithAnnotation:annotation reuseIdentifier:shopAnnotationIdentifier];
customPinView.image = [UIImage imageNamed:#"map_pin.png"];
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
TAPPMapAnnotation *theAnnotation = view.annotation;
TAPPMapAnnotationDetail *theController = [self.storyboard instantiateViewControllerWithIdentifier:#"MapAnnotationDetail"];
theController.theAnnotationId = theAnnotation.objectId;
[self.navigationController pushViewController:theController animated:YES];
}
TAPPMapAnnotationCustom.h
#import <MapKit/MapKit.h>
#interface TAPPMapAnnotationCustom : MKAnnotationView
#property (strong, nonatomic) UIImageView *calloutView;
#property (strong, nonatomic) UILabel *title;
#property (strong, nonatomic) UILabel *subTitle;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)animateCalloutAppearance:(BOOL)inAdd;
#end
TAPPMapAnnotationCustom.m
#import "TAPPMapAnnotationCustom.h"
#import "TAPPMapAnnotation.h"
#implementation TAPPMapAnnotationCustom
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
[super setSelected:selected animated:animated];
if(selected)
{
// Remove Image, because we set a second large one.
self.image = Nil;
UIImage *imageBack = [[UIImage imageNamed:#"map_pin.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 35, 0, 6)];
self.calloutView = [[UIImageView alloc]initWithImage:imageBack];
[self.calloutView setFrame:CGRectMake(0,0,0,0)];
[self.calloutView sizeToFit];
[self addSubview:self.calloutView ];
// Callout Button
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(openAnything) forControlEvents:UIControlEventTouchUpInside];
rightButton.frame = CGRectMake(0
, ((self.calloutView.frame.size.height-6) / 2)-(rightButton.frame.size.height / 2)
, rightButton.frame.size.width
, rightButton.frame.size.height);
self.rightCalloutAccessoryView = rightButton;
self.rightCalloutAccessoryView.hidden = YES;
self.rightCalloutAccessoryView.alpha = 0;
[self addSubview:self.rightCalloutAccessoryView];
// Start Annimation
[self animateCalloutAppearance:YES];
} else {
//Start Annimation and Remove from view
[self animateCalloutAppearance:NO];
}
}
- (void)didAddSubview:(UIView *)subview{
if ([[[subview class] description] isEqualToString:#"UICalloutView"]) {
for (UIView *subsubView in subview.subviews) {
if ([subsubView class] == [UIImageView class]) {
UIImageView *imageView = ((UIImageView *)subsubView);
[imageView removeFromSuperview];
}else if ([subsubView class] == [UILabel class]) {
UILabel *labelView = ((UILabel *)subsubView);
[labelView removeFromSuperview];
}
}
}
}
- (void)animateCalloutAppearance:(BOOL)inAdd {
if (inAdd == YES) {
self.rightCalloutAccessoryView.hidden = NO;
[UIView animateWithDuration:0.4 delay:0 options: UIViewAnimationOptionTransitionNone
animations:^{
self.calloutView.frame = CGRectMake(self.calloutView.frame.origin.x
, self.calloutView.frame.origin.y
, self.calloutView.frame.size.width+150
, self.calloutView.frame.size.height);
self.rightCalloutAccessoryView.alpha = 1;
self.rightCalloutAccessoryView.frame = CGRectMake(self.calloutView.frame.size.width - (self.rightCalloutAccessoryView.frame.size.width)
, self.rightCalloutAccessoryView.frame.origin.y
, self.rightCalloutAccessoryView.frame.size.width
, self.rightCalloutAccessoryView.frame.size.height);
} completion:^(BOOL finished){ }];
} else {
[UIView animateWithDuration:0.4 delay:0 options: UIViewAnimationOptionTransitionNone
animations:^{
self.rightCalloutAccessoryView.alpha = 0;
self.rightCalloutAccessoryView.frame = CGRectMake(0
, self.rightCalloutAccessoryView.frame.origin.y
, self.rightCalloutAccessoryView.frame.size.width
, self.rightCalloutAccessoryView.frame.size.height);
self.calloutView.frame = CGRectMake(self.calloutView.frame.origin.x
, self.calloutView.frame.origin.y
, self.calloutView.frame.size.width-150
, self.calloutView.frame.size.height);
} completion:^(BOOL finished){
self.image = [UIImage imageNamed:#"map_pin.png"];
[self.calloutView removeFromSuperview];
[self.rightCalloutAccessoryView removeFromSuperview];
}];
}
}
#end
Your annotation class needs to have a subtitle attribute, yours has subTitle.
If calloutAccessoryControlTapped is not being called it is usually a sign your MKMapview's delegate has not been set. However you're only setting the accessory button when it gets selected. Do you have a good reason for that? Since the callout window won't be visible until it is selected, I would advise you to set the accessory button in viewForAnnotation and let it appear when the callout window does.
I fix the first one:
TAPPMapAnnotation *theAnnotation = (TAPPMapAnnotation *)self.annotation;
self.title = [[UILabel alloc]init];
self.title.font = [UIFont systemFontOfSize:12.0];
self.title.textColor = [UIColor whiteColor];
self.title.backgroundColor = [UIColor clearColor];
self.title.text = theAnnotation.title;
[...]
[self.theView addSubview:self.title];
ı have a problem about scrollview.
my project about a newspaper.my problem about : I want to start at the
top of the page when changing page.
scrollview have 8 news.ı want to beginning at the top of the text on
the page when change 2. or 3. or.. news..
please help me about it.because ı need to deliver the project on Monday.for this reason ı
must do today or tomorrow.
code of project in here
myScrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
myScrollview.pagingEnabled = YES;
myScrollview.scrollEnabled =YES;
myScrollview.clipsToBounds = NO;
myScrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
myScrollview.showsHorizontalScrollIndicator = YES;
myScrollview.backgroundColor = [UIColor blackColor];
myScrollview.delegate = self;
NSInteger viewcount=4;
NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:#"photo1.png"],[UIImage imageNamed:#"photo2.png"],[UIImage imageNamed:#"photo3.png"],[UIImage imageNamed:#"photo4.png"],nil];
for (int i = 0; i <viewcount; i++)
{
CGFloat x = i * self.view.frame.size.width;
subView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
[subView setBackgroundColor:[UIColor blackColor]];
[subView setCanCancelContentTouches:NO];
subView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
subView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
aImageView = [[UIImageView alloc ] initWithImage:[images objectAtIndex:i]];
aImageView.frame=CGRectMake(0, 0, 320, 900);
[aImageView setTag:viewcount];
[subView addSubview:aImageView];
[subView setContentSize:CGSizeMake(aImageView.frame.size.width, subView.frame.size.height)];
subView.minimumZoomScale = 1;
subView.maximumZoomScale = 9;
subView.delegate = self;
[subView setScrollEnabled:YES];
subView.contentSize = aImageView.frame.size;
[myScrollview addSubview:subView];
}
myScrollview.contentSize = CGSizeMake(self.view.frame.size.width*viewcount,self.view.frame.size.height);
[self.view addSubview:myScrollview];
https://biliyomusunuz.com
I am developing an application in which i am displaying data from back-end.
Now the problem is as i am filling my table with for loop, and every cell of loop is filling data by every call. suppose there are 9 entries in the database, i want them to display as per row but all the 9 rows are filling by 9 entries by overlapping each other.
As i m new to iphone development, Please help me.
this is my piece of code m trying but not succeeded.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if(requestType == 2)
{
if (self.uniqueCityCount > 0)
{
NSString *strCity = [self.arrayCityNames objectAtIndex:section]; //#"EventData" :#"EventCity"
NSPredicate *predicateSettings = [NSPredicate predicateWithFormat:#"(EventCity = %# )",strCity];
if ([self.arrayEventDescription count]>0)
{
[self.arrayEventDescription removeAllObjects];
}
self.arrayEventDescription = [CoreDataAPIMethods searchObjectsInContext:#"EventData" :predicateSettings :#"EventCity" :YES :self.managedObjectContext];
return [self.arrayEventDescription count];
}
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImageView *imgEventLabel = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 480, 22)];
imgEventLabel.image = [UIImage imageNamed:#"city_date_place.png"];
UILabel *lblCity = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 200, 22)];
lblCity.font = [UIFont systemFontOfSize:14];
lblCity.backgroundColor = [UIColor clearColor];
lblCity.tag = 301;
//lblCity.backgroundColor = [UIColor redColor];
UILabel *lblDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 200, 22)];
lblDate.font = [UIFont systemFontOfSize:14];
lblDate.backgroundColor = [UIColor clearColor];
lblDate.tag = 302;
//lblDate.backgroundColor = [UIColor redColor];
UILabel *lblSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 00, 400, 22)];
lblSchool.font = [UIFont systemFontOfSize:14];
lblSchool.backgroundColor = [UIColor clearColor];
lblSchool.tag = 303;
//lblSchool.backgroundColor = [UIColor redColor];
[imgEventLabel addSubview:lblCity];
[imgEventLabel addSubview:lblDate];
[imgEventLabel addSubview:lblSchool];
return imgEventLabel;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 22;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [#"" stringByAppendingFormat:#"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if(requestType == 2)
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
for (int j = 0 ; j < [self.arrayEventDescription count]; j++)
{
NSLog(#"%d",indexPath.row);
//EventData *data = [self.arrayEventDescription objectAtIndex:indexPath.row];
EventData *data = [self.arrayEventDescription objectAtIndex:j];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
// UIView *viewDescription = [[UIView alloc]initWithFrame:CGRectMake(00, 00, 480, 35)];
////////////////////// Labels for description of city events from database ////////////////////////////
UILabel *lblEvent = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 150, 30)];
lblEvent.font = [UIFont systemFontOfSize:12];
lblEvent.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 150, 30)];
lblEventAtDate.font = [UIFont systemFontOfSize:12];
lblEventAtDate.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 15, 150, 30)];
lblEventAtSchool.font = [UIFont systemFontOfSize:12];
lblEventAtSchool.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblEvent];
[cell.contentView addSubview:lblEventAtDate];
[cell.contentView addSubview:lblEventAtSchool];
lblEvent.text = data.EventName;
//lblEventAtDate.text = data.EventDate;
lblEventAtSchool.text = data.EventPlace;
}
}
}
// Configure the cell...
return cell;
}
Don't loop through your array. Just get the element for the row that is being asked for (which is indexPath.row.)
cellForRowAtIndexPath: will be called as many times as you specify in numberOfRowsInSection:.
Just make one cell per call.
Im trying to create a UILabel subclass that will accomplish the task of the 2 separate UILabels i have stacked on top of each other using the following methods:
Background UILabel:
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
//UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 3);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
self.alpha = .1;
self.shadowOffset = shadowOffset;
}
Foreground UILabel:
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 2);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor blackColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.alpha = .5;
self.shadowOffset = shadowOffset;
}
Is there a way to accomplish these 2 sets of affects using only 1 UILabel subclass?
Try this code:
UILabel* label = [[UILabel alloc] init];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(0,1);