When using UIBUtton, we sometimes need to set pictures and text at the same time. The following code is for reference only:
UIButton * _ backButton = [UIButton
ButtonWithType: UIButtonTypeCustom];
[_ BackButton setFrame: CGRectMake (12,
8, 64, 28)];
[_ BackButton setTitle: @ "return"
ForState: UIControlStateNormal]; // sets the font of the button when it is not selected.
_ BackButton. titleLabel. font = [UIFont
SystemFontOfSize: 14.0f]; // set the font size of the button.
[_ BackButton setBackgroundImage: [UIImage
ImageNamed: @ "backButton.png"]
ForState: UIControlStateNormal]; // sets the button background to display the image.
[Self. view addSubview: _ backButton];
In the event of the above operation accident, we can also set the button to display different text and images in the selected (pressed) and normal (not selected) status,
UIButton * _ backButton = [UIButton
ButtonWithType: UIButtonTypeCustom];
[_ BackButton setFrame: CGRectMake (12,
8, 64, 28)];
[_ BackButton setTitle: @ "return"
ForState: UIControlStateNormal];
[_ BackButton setTitle: @ "Down" forState: UIControlStateHighlighted];
[_ BackButton setBackgroundColor: [UIColor clearColor];
[_ BackButton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
_ BackButton. titleLabel. font = [UIFont
SystemFontOfSize: 14.0f];
[_ BackButton setBackgroundImage: [UIImage
ImageNamed: @ "backButton.png"]
ForState: UIControlStateNormal];
[_ BackButton setBackgroundImage: [UIImage imageNamed: @ "DownButton.png"] forState: UIControlStateNormal];
[_ ToolBar addSubview: _ backButton];