Fscalendar: Feature Request: Change size of event dots

Created on 3 Dec 2016  路  6Comments  路  Source: WenchaoD/FSCalendar

Hello,

I'd like to know if there is a way to change the dot size for events. I didn't see a way exposed in the API, so I looked into the code and found two places where it controlled the size.

FSCalendarConstants.m
FSCalendarMaximumEventDotDiameter = 4.8
I changed 4.8 here to a higher value, such as 5.8.

FSCalendarCell
At the end of layoutSubviews:
CGFloat eventSize = _shapeLayer.frame.size.height/6.0;
I changed the divide by 6.0 here to a smaller value, such as 4.0.

With those changes the dot size got larger. I was wondering if there are other places in the code to change.

Thank you.

Most helpful comment

@WenchaoD please add this feature!

All 6 comments

Hi James,

Take a look at my forked branch - note that this was forked from FSCalendar 2.4.0, so files / file names may have changed.

Note the new properties: eventDotDiameter and preferredEventDotDiameter
(Also note the supporting code - it follows the existing FSCalendar method of updating the cell appearance.)

With this code in place, you'll easily be able to set the event dot diameter to whatever you'd like, e.g.: calendar.appearance.eventDotDiameter = 5.8

I am hoping to do a pull request soon to get this integrated into the library.

@h-bomb Awesome, I'll check it out. Thanks.

@WenchaoD please add this feature!

@h-bomb Awesome, I'll check it out. Thanks.

How to do it in my project? This feature not yet added in library. Help me to do this

Hi, guys. The above answer is too old to import into our project.
So, I wrote a CustomCalendarCell with a minimum of code to draws a new Dot the size I want.
See the code below. I Hope it helps.

import FSCalendar

class CustomCalendarCell: FSCalendarCell {

    private var eventDotSize: CGFloat = 4.0
    private lazy var newDotView: UIView = {
        let view = UIView()
        return view
    }()

    override func layoutSubviews() {
        super.layoutSubviews()

        eventIndicator.subviews.first?.alpha = 0.0 // hide dots of library

        let newDotRect = CGRect(x: (frame.width - eventDotSize) / 2,
                                y: eventDotSize / 2,
                                width: eventDotSize,
                                height: eventDotSize)

        newDotView.frame = newDotRect
        newDotView.backgroundColor = .red // {You want}
        newDotView.layer.cornerRadius = eventDotSize / 2
        eventIndicator.addSubview(newDotView)
    }
}

Don't forget to add the code below.

calendar.register(CustomCalendarCell.self, forCellReuseIdentifier: "cell")
func calendar(_ calendar: FSCalendar, cellFor date: Date, at position: FSCalendarMonthPosition) -> FSCalendarCell {
    return calendar.dequeueReusableCell(withIdentifier: "cell", for: date, at: position)
}

Why so complicated?
Just do this:

func calendar(_ calendar: FSCalendar, willDisplay cell: FSCalendarCell, for date: Date, at monthPosition: FSCalendarMonthPosition) {
    let eventScaleFactor: CGFloat = 0.8
    cell.eventIndicator.transform = CGAffineTransform(scaleX: eventScaleFactor, y: eventScaleFactor)
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kunass2 picture kunass2  路  4Comments

KushThakkar picture KushThakkar  路  6Comments

ghost picture ghost  路  5Comments

divya417 picture divya417  路  6Comments

thaoth58 picture thaoth58  路  3Comments