Skip to content

Instantly share code, notes, and snippets.

View ankushkushwaha's full-sized avatar

Ankush ankushkushwaha

View GitHub Profile
@ankushkushwaha
ankushkushwaha / MapKitView.swift
Created January 3, 2025 09:32
MapKit marker following a route animation
import SwiftUI
import MapKit
struct MapKitView: View {
@State private var selectedResult: MKMapItem?
@State private var route: MKRoute?
@State private var markerCoordinate: CLLocationCoordinate2D
@State private var timer: Timer?
@State private var pathCoordinates: [CLLocationCoordinate2D] = []
@State private var currentIndex: Int = 0
@ankushkushwaha
ankushkushwaha / Calculate_Label_Height.m
Created June 27, 2015 10:17
Calculate Label Height dynamically in iOS
/**
* Calculate height for a fixed weidht label
* @param UILabel for which height to be calculated
**/
-(double)getLabelHeightForLabel:(UILabel *)label{
CGSize constrainedSize = CGSizeMake(label.frame.size.width, 1000);
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: label.font, NSFontAttributeName,nil];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:label.text attributes:attributesDictionary];
CGRect requiredHeight = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];