Unable to get the title from PKAddPassButton

Dear team,
I am unable to get the title from PKAddPassButton. Please see the Objective C code block:

PKAddPassButton *button = [[PKAddPassButton alloc] initWithAddPassButtonStyle:PKAddPassButtonStyleBlackOutline];
  NSString *title = [button currentTitle];
  NSLog(@"Title %@", title);

Output :
Title (null)

What could be wrong in this? Kindly help.
You have to set title explicitly:
Swift
Code Block
          button.setTitle("Some title", for: .normal)

objC: use
  • (void)setTitle:(NSString *)title forState:(UIControlState)state;

should be like
Code Block
[button setTitle:@"Some Title" forState:UIControlEventAllEvents];

What could be wrong in this?

PKAddPassButton is actually a subclass of UIButton, but it does not mean all the properties or methods work the same as UIButton.

As far as I checked, PKAddPassButton has some private UILabels and the actually shown text is held in one of them.
(You may find that title would appear overlapping the existing title of PKAddPassButton, if you call setTitle:.)

You could explore the subviews of the button and get or set the text of the label.
But this sort of view hierarchy would change at any time in the future, at any time without notifications.

Considering why Apple made such UILabels private, modifying the contents of such labels might be taken as using private APIs.
Unable to get the title from PKAddPassButton
 
 
Q