FSCalendar+Persian: How to change weekday order? - objective-c

I'm using Objective-c in my project, and using FSCalendar+Persian pod.
this is my code for showing calendar:
calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, _calendarContainer.frame.size.width, _calendarContainer.frame.size.height)];
calendar.locale = [NSLocale localeWithLocaleIdentifier:#"fa_IR"];
calendar.calendarIdentifier = NSCalendarIdentifierPersian;
calendar.firstWeekday = 1;
calendar.placeholderType = FSCalendarPlaceholderTypeNone;
calendar.dataSource = self;
calendar.delegate = self;
calendar.appearance.headerTitleColor = [UIColor primaryColor];
calendar.appearance.headerTitleFont = [UIFont fontWithName:NSLocalizedString(#"DefaultFontBold", #"") size:15];
calendar.appearance.weekdayTextColor = [UIColor primaryColor];
calendar.appearance.selectionColor = [UIColor clearColor];
calendar.appearance.borderSelectionColor = [UIColor primaryColor];
calendar.appearance.titleSelectionColor = [UIColor primaryColor];
calendar.appearance.titleDefaultColor = [UIColor primaryColor];
calendar.appearance.todayColor = [UIColor primaryColor];
calendar.appearance.titleTodayColor = [UIColor whiteColor];
calendar.appearance.titleFont = [UIFont fontWithName:NSLocalizedString(#"DefaultFont", #"") size:14];
calendar.appearance.titleWeekendColor = [UIColor redColor];
calendar.calendarWeekdayView.weekdayLabels[5].textColor = [UIColor redColor];
[_calendarContainer addSubview:calendar];
In my country the first week day is saturday(شنبه), and the last week day is Friday(جمعه).
my problem is I want first week day to be the first column from the right side not the left side and the last week day be the first column from the left side.
how can I fix this problem?

I found what is the problem, the problem is in this line of code:
calendar.locale = [NSLocale localeWithLocaleIdentifier:#"fa_IR"];
I must change fa_IR to fa-IR (change underline to dash) and the problem solved.

Related

UItextfield adding extra spaces beneath timestamp

I have a relatively simple comment box (UITextfield) for a photo app into which I've found that when entering long comments (usually more than half a dozen words) a lot of blank space appears below the timestamp ("X minutes ago") within the comment box. The longer the post, the more blank space appears within the box. Everything else works fine, the comment is vertically aligned correctly, and the timestamp is directly below this.
self.backgroundColor = [UIColor clearColor];
mainView = [[UIView alloc] initWithFrame:CGRectMake( 20.0f, 0.0f, 280.0f, 51.0f)];
mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundComments.png"]];
[self addSubview:mainView];
UIImageView *messageIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"IconAddComment.png"]];
messageIcon.frame = CGRectMake( 9.0f, 17.0f, 19.0f, 17.0f);
[mainView addSubview:messageIcon];
UIImageView *commentBox = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:#"TextFieldComment.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5.0f, 10.0f, 5.0f, 10.0f)]];
commentBox.frame = CGRectMake(35.0f, 8.0f, 237.0f, 35.0f);
[mainView addSubview:commentBox];
commentField = [[UITextField alloc] initWithFrame:CGRectMake( 40.0f, 10.0f, 227.0f, 31.0f)];
commentField.font = [UIFont systemFontOfSize:14.0f];
commentField.placeholder = #"Add a comment";
commentField.returnKeyType = UIReturnKeySend;
commentField.textColor = [UIColor colorWithRed:73.0f/255.0f green:55.0f/255.0f blue:35.0f/255.0f alpha:1.0f];
commentField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[commentField setValue:[UIColor colorWithRed:154.0f/255.0f green:146.0f/255.0f blue:138.0f/255.0f alpha:1.0f] forKeyPath:#"_placeholderLabel.textColor"];
[mainView addSubview:commentField];
Any help would be much appreciated!

self.navigationItem.titleView cutting off UIBarButtonItem after rotation

I use a self.navigationItem.titleView and I set two UIButtons as the self.navigationItem.rightBarButtonItems in the UINavigationBar. I have achieved this in my navigationBar like so
Whenever I rotate the view controller landscape and then back, the uibarbutton item gets cut off like so
The code I use to set the titleView is this:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.numberOfLines = 2;
titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];
titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = self.tabTitle;
self.navigationItem.titleView = titleLabel;
I have no idea why this is happening and I wonder if if any of you know how to fix this.

Section title not wrapping

I am trying to wrap my section header and UILineBreakModeWordWrap is not helping. Any idea what I am doing wrong?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *rOView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] ;
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
sectionLabel.backgroundColor = [UIColor clearColor];
sectionLabel.font = [UIFont boldSystemFontOfSize:18];
sectionLabel.frame = CGRectMake(70,18,200,20);
sectionLabel.text = #"A really really long text A really really long text A really really long text";
sectionLabel.textColor = [UIColor blueColor];
sectionLabel.numberOfLines = 0;
sectionLabel.lineBreakMode = UILineBreakModeWordWrap;
[roView addSubview:sectionLabel];
return roView;
}
You've not given the label a meaningful frame - only CGRectZero. After setting up your label, call -sizeToFit on it, like so:
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
sectionLabel.backgroundColor = [UIColor clearColor];
sectionLabel.font = [UIFont boldSystemFontOfSize:18];
sectionLabel.frame = CGRectMake(70,18,200,20);
sectionLabel.text = #"A really really long text A really really long text A really really long text";
sectionLabel.textColor = [UIColor blueColor];
sectionLabel.numberOfLines = 0;
sectionLabel.lineBreakMode = UILineBreakModeWordWrap;
[sectionLabel sizeToFit];
Edit: I see now that you did actually set the label frame. But the height is too short to display all the text.

change a uitableviewcell subview UILabel text

This is how my tableviewcell is setup
else if(indexPath.row == 3)
{
cell.textLabel.text = #"Category";
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = #"select a category";
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
[categoryLabel release];
}
I need to change the the text of the category label later on in the program.
How do I accomplish this? I assume I need to use the tag to reference the UILabel?
This is how my tableviewcell is setup
else if(indexPath.row == 3)
{
cell.textLabel.text = #"Category";
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = #"select a category";
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
[categoryLabel release];
}
I need to change the the text of the category label later on in the program. How do I accomplish this? I assume I need to use the tag to reference the UILabel?
========================
I figured it out...
I put the UILabel in my header file and changed the code like so
else if(indexPath.row == 3)
{
cell.textLabel.text = #"Category";
categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = [NSString stringWithFormat:#"%#",categoryFriendlyString];
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
}
Then when I wanted to change it later I did this
categoryLabel.text = #"sample string";
And finally released it in my dealloc method.

Loading data issue in UITableview

I created an application using UITableView. I parsing the data from URL and listed in UITableView.
But in UITableView, the first the data only displayed again and again.
I don't know why this problem occurred.
My code is as below:
-(UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
CGRect frame = CGRectMake(10.0f, 5.0, 300.0, 55);
valueField = [[UILabel alloc] initWithFrame:frame];
[valueField setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
valueField.tag = 111;
valueField.font=[UIFont fontWithName:#"Helvetica" size:16.0];
valueField.textAlignment = UITextAlignmentLeft;
valueField.lineBreakMode=UILineBreakModeWordWrap;
valueField.numberOfLines = 0;
valueField.textColor = [UIColor whiteColor];
valueField.highlightedTextColor = [UIColor whiteColor];
valueField.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
valueField.adjustsFontSizeToFitWidth = YES;
valueField.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
valueField.text=[title1 objectAtIndex:count1];
[cell.contentView addSubview:valueField];
UIImage *favOn = [UIImage imageNamed:#""];
UIImage *favOff = [UIImage imageNamed:#""];
titlebutton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, 15.0, 300.0, 55)];
[titlebutton setTag:indexPath.row];
//titlebutton.tag = 111;
[titlebutton setImage:favOff forState:UIControlStateNormal];
[titlebutton setImage:favOn forState:UIControlStateSelected];
if([self getFavState:#"111"])
{
[titlebutton setSelected:YES];
}
else
{
[titlebutton setSelected:NO];
}
[titlebutton addTarget:self action:#selector(favButtonSwitch:) forControlEvents:UIControlEventTouchUpInside];
[titlebutton setBackgroundColor:[UIColor clearColor]];
[titlebutton setTitle:#"" forState:UIControlStateNormal];
[cell.contentView addSubview:titlebutton];
CGSize labelSize = [valueField.text sizeWithFont:valueField.font constrainedToSize:valueField.frame.size lineBreakMode:UILineBreakModeWordWrap];
int labelHeight = labelSize.height;
NSLog(#"labelHeight = %d", labelHeight);
frame = CGRectMake(10.0f, 40.0, 300.0, 55);
pubField = [[UILabel alloc] initWithFrame:frame];
[pubField setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
pubField.tag = 111;
pubField.font=[UIFont fontWithName:#"Helvetica" size:12.0];
pubField.textAlignment = UITextAlignmentLeft;
pubField.lineBreakMode=UILineBreakModeWordWrap;
pubField.numberOfLines = 0;
pubField.textColor = [UIColor whiteColor];
pubField.highlightedTextColor = [UIColor whiteColor];
pubField.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
pubField.adjustsFontSizeToFitWidth = YES;
pubField.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
pubField.text=[pubDate objectAtIndex:indexPath.row];
[cell.contentView addSubview:pubField];
frame = CGRectMake(5.0, 70.0, 300.0, 55);
desField = [[UILabel alloc] initWithFrame:frame];
[desField setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
desField.tag = 111;
desField.font=[UIFont fontWithName:#"Helvetica" size:13.0];
desField.textAlignment = UITextAlignmentLeft;
desField.lineBreakMode=UILineBreakModeWordWrap;
desField.numberOfLines = 0;
desField.textColor = [UIColor whiteColor];
desField.highlightedTextColor = [UIColor whiteColor];
desField.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
desField.adjustsFontSizeToFitWidth = YES;
desField.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
desField.text=[description objectAtIndex:indexPath.row];
[cell.contentView addSubview:desField];
}
UIImage *patternImage = [UIImage imageNamed:#"bg.jpg"];
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithPatternImage: patternImage];
cell.backgroundView = backView;
NSString *image1 =[images objectAtIndex:indexPath.row];
NSLog(#"Images ..... = %#",image1);
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[images objectAtIndex:indexPath.row]]];
UIImage *myimage = [[UIImage alloc] initWithData:mydata];
UIImageView *imageView = [ [ UIImageView alloc ] initWithImage: myimage ];
imageView.frame = CGRectMake(10.0f, 110.0f, 120.0f, 120.0f);
[cell.contentView addSubview:imageView];
return cell;
}
do all the alloc/init and all things, that will be the same in any cell in the
if(cell==nil){
//<-- here
}
while setting text and any thing that changes by the specific data outside the block
if(cell==nil){
}
//<-- here
i.e:
if(cell==nil){
//....
valueField.tag = 111;
valueField.font = [UIFont fontWithName:# "Helvetica" size:16.0];
valueField.textAlignment = UITextAlignmentLeft;
valueField.lineBreakMode = UILineBreakModeWordWrap;
valueField.numberOfLines = 0;
valueField.textColor = [UIColor whiteColor];
valueField.highlightedTextColor = [UIColor whiteColor];
valueField.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
valueField.adjustsFontSizeToFitWidth = YES;
valueField.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[cell.contentView addSubview : valueField];
//....
}
//....
valueField.text = [title1 objectAtIndex:count1];
//....
the first cell data is getting displayed in all the cells because when you initialize and create your reusable cell, you fill the data there, you need to initialize a reusable cell that doesnt have all its values set, and then set this information for each cell. That is, you need to have all the information you want for each particular cell outside the if(cell==nil) part of this code, and rely on the indexPath to know which cell you are in, and feed in different data based on this.
You seem to be constructing the subviews of the cell correctly when there is no reusable cell available. The question is, what does your code do when you do dequeue a reusable cell? It appears that you do nothing. You should move any row-specific initialization (setting label text values, images, etc.) outside the check for whether the dequeued cell is nil. In this way, whether you just constructed a new cell or dequeued a previously-created cell, the data being displayed correctly correlates to the row being displayed.
Well actually your code this way is quite hard to decode,
but first of all, you declare a lot of tag that should be used to retrieve the UIViews you're declaring.
Unfortunately these are all the same (tags) so you might never get what you want. You should maybe put in some constant in your header file like:
#define kPubLabel 100
then use them.
then you usually retrieve these after declaring your cell to populate them.
In the mean time, retrieving your images from url in this method is one of the best way to have your application being slow, since each time you scroll, you'll have to re-fetch your image from where it come from causing your table view to "freeze".
Finally, the only thing that might change, according to your code is the imageView that you add to your frame. You usually have an ImageView in which you put an image that you might have stored/cached but rarely change the contentView of a cell.
ie
Maybe you should externalize your cell building code in a class overriding UITableViewCell.
Put different tags on every element in your cell to retrieve them in your method.
Retrieve your elements in your method according to there tags.
Populate and only populate them in your method.
Retrieve your image once and for all for performance improval.
I'm not sure this will help, but in my point of view, there are actually a lot work to do in your code.