iOS  Tree

"All of us do not have equal talent. But , all of us have an equal opportunity to develop our talents.” – A.P.J Abdul Kalam

Get Font Family names within your app — September 29, 2017

Get Font Family names within your app

Get all font names to be used within your app, including the custom fonts.
Objective C:
for (NSString *familyName in [UIFont familyNames]){
    NSLog(@"Family name: %@", familyName);
    for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
      NSLog(@"--Font name: %@", fontName);
   }
}

Swift 2:
for familyName:AnyObject in UIFont.familyNames() {
    print("Family Name: \(familyName)")
    for fontName:AnyObject in UIFont.fontNamesForFamilyName(familyName as! String) {
      print("--Font Name: \(fontName)")
    }
}

Swift 3:
for familyName:String in UIFont.familyNames {
    print("Family Name: \(familyName)")
    for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
      print("--Font Name: \(fontName)")
    }
}

UITapGestureRecognizer get touched view — September 11, 2017

UITapGestureRecognizer get touched view

Objective C:
Add UITapGestureRecognizer to yourView

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGestureRecognizer:)];
[self.yourView setUserInteractionEnabled:YES];
[self.yourView addGestureRecognizer:tapGestureRecognizer];

#pragma mark - Handle TapGestureRecognizer
- (void)handleTapGestureRecognizer:(UITapGestureRecognizer*)sender{
    UIView* view = sender.view;//youView
    CGPoint viewLocation = [sender locationInView:view];
    UIView* subview = [view hitTest:viewLocation withEvent:nil];
}

Swift 3.0:
Add UITapGestureRecognizer to yourView

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.handleTapGestureRecognizer(_:)))
yourView.isUserInteractionEnabled = true yourView.addGestureRecognizer(tapGestureRecognizer)

//MARK:- Handle TapGestureRecognizer
func handleTapGestureRecognizer(_ sender: UITapGestureRecognizer){
   let view = sender.view //youView
  let viewLocation = sender.location(in: view)
  let subview = view?.hitTest(viewLocation, with: nil)//Getting subview as UIView?
}