navigationbar setBackgroundImage not working on iOS15 - ios15

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

Related

Programmatically showing new window/view when selecting UICollectionViewCell

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

UITextView does not display text

In my viewDidLoad I can get UILabels and UITextFields to display text but not a UITextView. Am I doing something wrong in the code below?
- (void)viewDidLoad {
[super viewDidLoad];
UIView* headerWrapper = [[UIView alloc] init];
//tap gesture is for each section so we can click on it
UITapGestureRecognizer *headerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(showContent:)];
header = [[UIView alloc] initWithFrame: CGRectMake(10.0, 10.0, 738.0, 40.0)];
header.backgroundColor = [UIColor blackColor];
//get the header frame
CGRect headerFrame = header.frame;
//add the gesture
[headerWrapper addGestureRecognizer:headerTap];
//add a label
UILabel* lblSectionTitle = [[UILabel alloc] initWithFrame: CGRectMake(10.0, 3.0, headerFrame.size.width, 24.0)];
lblSectionTitle.text = #"This is a test";
lblSectionTitle.font = [UIFont fontWithName:#"Helvetica" size:20.0];
lblSectionTitle.textColor = [UIColor whiteColor];
lblSectionTitle.backgroundColor = [UIColor clearColor];
[header addSubview:lblSectionTitle];
[headerWrapper addSubview:header];
//this is the wrapper for the content
UIView* contentView = [[UIView alloc] initWithFrame:CGRectMake(10.0, headerFrame.size.height + 15.0, headerFrame.size.width, 200.0)];
contentView.backgroundColor = [UIColor redColor];
UITextView* tvContent = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, headerFrame.size.width, 200.0)];
[tvContent setText:#"This is a content test."];
tvContent.textColor = [UIColor blackColor];
tvContent.backgroundColor = [UIColor clearColor];
tvContent.font = [UIFont fontWithName:#"Trebuchet" size:18.0];
[contentView addSubview:tvContent];
[headerWrapper addSubview:contentView];
[self.view addSubview:headerWrapper];
NSLog(#"%#", tvContent.text);
}
I just had this problem today and solved it by changing:
[tvContent setText:#"This is a content test."];
to
tvContent.text = #"This is a content test.";
At first I thought the problem was with not having my UITextView loaded. But after I made sure it was loaded and connected in the interface builder (not your case since you are doing it programmatically), I could only set its content by doing direct attribution instead of calling setText.
Hope it helps!

UILabels NOT Updating

I have a UITableView that is being populated by core data. Now, when I click on a cell, it pushes me to another view where I can edit the data that is in that particular index, when I return, the system either crashes or else doesn't load the changes onto the labels, any ideas? code below
-(void)viewWillAppear:(BOOL)animated
{
searchCriteria = [[NSMutableString alloc] initWithString:#"clientName"];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"clientName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Client" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:#"Root"];
[self.clientTableView reloadData];
[super viewWillAppear:animated];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath];
clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)];
clientNameLabel.tag = 1;
clientNameLabel.backgroundColor = [UIColor clearColor];
clientNameLabel.textColor = [UIColor whiteColor];
clientNameLabel.font = [UIFont boldSystemFontOfSize:13];
clientNameLabel.text = client.clientName;
[cell.contentView addSubview:clientNameLabel];
clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)];
clientAccountNumberLabel.tag = 2;
clientAccountNumberLabel.textColor = [UIColor whiteColor];
clientAccountNumberLabel.backgroundColor = [UIColor clearColor];
clientAccountNumberLabel.font = [UIFont boldSystemFontOfSize:13];
clientAccountNumberLabel.text = client.clientAccountNumber;
[cell.contentView addSubview:clientAccountNumberLabel];
clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)];
clientTelephoneNumberLabel.tag = 3;
clientTelephoneNumberLabel.textColor = [UIColor whiteColor];
clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor];
clientTelephoneNumberLabel.font = [UIFont boldSystemFontOfSize:13];
[cell.contentView addSubview:clientTelephoneNumberLabel];
addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine1Label.tag = 4;
addressLine1Label.textColor = [UIColor whiteColor];
addressLine1Label.backgroundColor = [UIColor clearColor];
addressLine1Label.font = [UIFont boldSystemFontOfSize:13];
addressLine1Label.text = client.addressLine1;
[cell.contentView addSubview:addressLine1Label];
addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine2Label.tag = 5;
addressLine2Label.textColor = [UIColor whiteColor];
addressLine2Label.backgroundColor = [UIColor clearColor];
addressLine2Label.text = client.addressLine2;
addressLine2Label.font = [UIFont boldSystemFontOfSize:13];
[cell.contentView addSubview:addressLine2Label];
addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine3Label.tag = 6;
addressLine3Label.textColor = [UIColor whiteColor];
addressLine3Label.backgroundColor = [UIColor clearColor];
addressLine3Label.font = [UIFont boldSystemFontOfSize:13];
addressLine3Label.text = client.addressLine3;
[cell.contentView addSubview:addressLine3Label];
addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine4Label.tag = 7;
addressLine4Label.textColor = [UIColor whiteColor];
addressLine4Label.backgroundColor = [UIColor clearColor];
addressLine4Label.font = [UIFont boldSystemFontOfSize:13];
addressLine4Label.text = client.addressLine4;
[cell.contentView addSubview:addressLine4Label];
return cell;
}
The Crash Logs are as follows:
2012-06-23 17:08:05.541 iSalesForce[11773:15803] no object at index 1 in section at index 0
And some other code you might find useful are:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fetchedObjects count];
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70.0;
}
The problem is most likely in the fact your fetchedResultsController has gone stale (are you using ARC? is that fetchedResultsController a "strong" property?
Or it may simply be that your fetchedResultsController has no objects and you're insisting that you have exactly one object in your "numberOfSectionsInTableView" method, regardless of the true contents of "fetchedResultsController".
Try this new & improved function:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(cell == nil)
{
// this should never happen, but just in case...
NSLog( #"cell is still - unexpectedly - nil" );
} else {
if(self.fetchedResultsController == nil)
{
NSLog( #"surprise, fetchedResultsController is nil" );
} else {
Client * client = nil;
#try {
client = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
#catch (NSException * e) {
NSLog( #"exception thrown while trying to fetch something from fetchedResultsController - %# %#", [e name], [e reason] );
}
#finally {
clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)];
clientNameLabel.tag = 1;
clientNameLabel.backgroundColor = [UIColor clearColor];
clientNameLabel.textColor = [UIColor whiteColor];
clientNameLabel.font = [UIFont boldSystemFontOfSize:13];
clientNameLabel.text = client.clientName;
[cell.contentView addSubview:clientNameLabel];
clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)];
clientAccountNumberLabel.tag = 2;
clientAccountNumberLabel.textColor = [UIColor whiteColor];
clientAccountNumberLabel.backgroundColor = [UIColor clearColor];
clientAccountNumberLabel.font = [UIFont boldSystemFontOfSize:13];
clientAccountNumberLabel.text = client.clientAccountNumber;
[cell.contentView addSubview:clientAccountNumberLabel];
clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)];
clientTelephoneNumberLabel.tag = 3;
clientTelephoneNumberLabel.textColor = [UIColor whiteColor];
clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor];
clientTelephoneNumberLabel.font = [UIFont boldSystemFontOfSize:13];
[cell.contentView addSubview:clientTelephoneNumberLabel];
addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine1Label.tag = 4;
addressLine1Label.textColor = [UIColor whiteColor];
addressLine1Label.backgroundColor = [UIColor clearColor];
addressLine1Label.font = [UIFont boldSystemFontOfSize:13];
addressLine1Label.text = client.addressLine1;
[cell.contentView addSubview:addressLine1Label];
addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine2Label.tag = 5;
addressLine2Label.textColor = [UIColor whiteColor];
addressLine2Label.backgroundColor = [UIColor clearColor];
addressLine2Label.text = client.addressLine2;
addressLine2Label.font = [UIFont boldSystemFontOfSize:13];
[cell.contentView addSubview:addressLine2Label];
addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine3Label.tag = 6;
addressLine3Label.textColor = [UIColor whiteColor];
addressLine3Label.backgroundColor = [UIColor clearColor];
addressLine3Label.font = [UIFont boldSystemFontOfSize:13];
addressLine3Label.text = client.addressLine3;
[cell.contentView addSubview:addressLine3Label];
addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)];
addressLine4Label.tag = 7;
addressLine4Label.textColor = [UIColor whiteColor];
addressLine4Label.backgroundColor = [UIColor clearColor];
addressLine4Label.font = [UIFont boldSystemFontOfSize:13];
addressLine4Label.text = client.addressLine4;
[cell.contentView addSubview:addressLine4Label];
}
Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
}
return cell;
}
(I didn't actually test this out... but I did put some new error checking and exception handling into it for you)

for-loop in uitableview

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.

Creating a stroke and shadow affect using only 1 UILabel subclass

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

Resources