Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add separator lines between the dates #39

Open
RamChandraReddy opened this issue Sep 15, 2014 · 17 comments
Open

How to add separator lines between the dates #39

RamChandraReddy opened this issue Sep 15, 2014 · 17 comments

Comments

@RamChandraReddy
Copy link

Hi,

I customised calendar view as
screen shot 2014-09-15 at 1 54 28 pm

But need to addd senator lines between the dates as showed below.
screen shot 2014-09-15 at 1 50 55 pm
I have tried to get the info where to add the lines. But couldn't able to find it.

Can some one let me know the way to do that .

Thanks in advance.

@RamChandraReddy RamChandraReddy changed the title How to add separator lines as showed in the folioing image How to add separator lines between the dates Sep 15, 2014
@k06a
Copy link
Owner

k06a commented Sep 15, 2014

Horizontal line can be implemented as part of buttons background image. You need white rect with single top edge line.

@RamChandraReddy
Copy link
Author

Hi,

I tried like adding one view to that button as below.
UIView *topBarVIew=[[UIView alloc]initWithFrame:CGRectMake(0, 5, self.frame.size.width, 1)];
topBarVIew.backgroundColor=[UIColor lightGrayColor];
topBarVIew.alpha=0.2;
[self addSubview:topBarVIew];

The outcome is like
screen shot 2014-09-15 at 3 58 50 pm

Now the problem is, the top border has to come like

screen shot 2014-09-15 at 4 00 51 pm

How do I know when to stop the border line ? so that it displays from 1st of every month and ends at last day of the month.

Thanks in advance.

@k06a
Copy link
Owner

k06a commented Sep 15, 2014

You can just use UIButton's method setBackgroungImage:forState: for state normal.

@k06a
Copy link
Owner

k06a commented Sep 15, 2014

So only current months tiles are in normal state. Next and prev month tiles are in disabled state. You should use nil image for disabled state.

@RamChandraReddy
Copy link
Author

Hi,

I tried to set background image to the button as below.
[button setBackgroundImage:[UIImage imageNamed:@"divider_red"] forState:UIControlStateNormal];

but the outcome is not as per expected.it's as follows.

screen shot 2014-09-16 at 11 11 44 am

It has gaps between the dates.It must be because of the space between the buttons. So it will not help if I set nil image four disabled state.
Need to find out some other way of handling this.

@k06a
Copy link
Owner

k06a commented Sep 16, 2014

You can use your trick with thin subview.

topBarVIew.tag = 555;
[self addSubview:topBarVIew];

Just in method - (void)setDisabled:(BOOL)disabled add line:

[self viewWithTag:555].hidden = disabled;

@RamChandraReddy
Copy link
Author

Hey where to add this - (void)setDisabled:(BOOL)disabled {
[self viewWithTag:555].hidden = disabled; } and from where I need to call this method.

Sorry for more questions. Because I tried to implement this, but couldn't understand exactly.

Thanks in advance.

@k06a
Copy link
Owner

k06a commented Sep 16, 2014

Every tile in calendar is really UIControl subclass and setDisabled:YES is called automatically for days of prev and next month. You should override this method and call super method inside.

@k06a
Copy link
Owner

k06a commented Sep 16, 2014

Oh sorry, method name is setEnabled:

@k06a
Copy link
Owner

k06a commented Sep 16, 2014

@RamChandraReddy
Copy link
Author

Hey,

I have added the topBarView as below in UIMyButton.

  • (void)drawRect:(CGRect)rect
    {
    NSString * titleText = [self titleForState:self.state];
    UIColor * titleColor = [self titleColorForState:self.state];
    UIColor * titleShadowColor = [self titleShadowColorForState:self.state];
    CGSize titleShadowOffset = [self titleShadowOffsetForState:self.state];
    //UIImage * backgroundImage = [self backgroundImageForState:self.state];
    //UIEdgeInsets capInsects = [self backgroundImageCapInsetsForState:self.state];
    NSString * dotsText = [@"" stringByPaddingToLength:self.numberOfDots withString:@"•" startingAtIndex:0];
    UIColor *dotColor;
    if (titleColor == [UIColor clearColor])
    {
    dotColor = titleColor;
    }
    else
    {
    dotColor = [UIColor redColor]; //colorWithPatternImage:[UIImage imageNamed:@"red_dot"]];
    }
    UIFont * titleFont = self.tileTitleFont;
    UIFont * dotsFont = self.tileDotFont;

    CGSize titleSize = [titleText sizeWithFont:titleFont];
    CGSize dotsSize = [dotsText sizeWithFont:dotsFont];
    CGSize size=dotsSize;
    size.height=3;
    size.width=3;
    dotsSize=size;

    CGPoint titlePoint = CGPointMake((self.bounds.size.width - titleSize.width)/2,
    (self.bounds.size.height - titleSize.height)/2);
    CGPoint dotsPoint = CGPointMake((self.bounds.size.width - dotsSize.width)/2,
    self.bounds.size.height*3/5+4);

    [titleColor set];
    CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), titleShadowOffset, 0.0, titleShadowColor.CGColor);

    [titleText drawAtPoint:titlePoint withFont:titleFont];

    if (self.numberOfDots > 0)
    [dotColor set];
    [dotsText drawAtPoint:dotsPoint withFont:dotsFont];

    // topBarVIew=nil;
    self.topBarView=[[UIView alloc]initWithFrame:CGRectMake(0, 5, self.frame.size.width, 1)];
    self.topBarView.backgroundColor=[UIColor lightGrayColor];
    self.topBarView.alpha=0.2;
    self.topBarView.tag=555;
    [self addSubview:self.topBarView];
    }

And setEnable method is like below.

  • (void)setEnabled:(BOOL)enabled
    {
    NSLog(@"enabled %d",enabled);
    if (!enabled) {
    if ([self viewWithTag:555]) {
    [[self viewWithTag:555].hidden=enabled;
    [[self viewWithTag:555]removeFromSuperview];
    NSLog(@"view exists");
    }
    }
    NSLog(@"subviews are %@",self.subviews);
    if (self.enabled == enabled)
    return;
    [super setEnabled:enabled];
    [self layoutSubviews];
    [self setNeedsDisplay];
    }

Every time it prints the subviews array as empty.It means [[self viewWithTag:555].hidden=enabled; doesn't help us to do this.
The current output is as follows.
screen shot 2014-09-16 at 6 36 23 pm

Can you let me know where it went wrong in my code.

Thanks in advance.

@k06a
Copy link
Owner

k06a commented Sep 16, 2014

You can not to use tagging at all if you have a property self.topBarView. Just hide it: self.topBapView.hidden = !enabled;.

And use single backticks for source code on github and triple backticks for source code blocks :)

@RamChandraReddy
Copy link
Author

Hey it didn't solve the issue. self.topBapView.hidden = !enabled;. doesn't help us. :(

@RamChandraReddy
Copy link
Author

Hey found the trick.

if (enabled) {
self.topBarView=nil;
self.topBarView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, self.frame.size.width, 1)];
self.topBarView.backgroundColor=[UIColor colorWithRed:234.0f/255.0f green:234.0f/255.0f blue:234.0f/255.0f alpha:1.0f];
self.topBarView.tag=555;
[self addSubview:self.topBarView];
}
else
{
for (UIView *view in self.subviews) {
if (view.tag==555) {
[view setHidden:YES];
}
}
}
It solves the issue. :) Thanks for your help.

Regards
Ram

@RamChandraReddy
Copy link
Author

Hey ,
May I know how to increase dot size?

@k06a
Copy link
Owner

k06a commented Sep 18, 2014

You can just increase font size

Repository owner deleted a comment from YeMyoAung Jan 31, 2024
Repository owner deleted a comment from gitChang Feb 23, 2024
Repository owner deleted a comment from technosoft-admin Mar 4, 2024
Repository owner deleted a comment from leocsilva Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@k06a @RamChandraReddy and others