UPDATE: Corrected the text and image of the button properties.
I am trying to show a button if specific information is available and have that button perform an action when clicked; Otherwise, just show a label. I have created the following:
if(rec.biography != nil)
{
btnProviderBio = [UIButton buttonWithType:UIButtonTypeCustom];
[btnProviderBio setImage:[UIImage imageNamed:@"info.png"] forState:UIControlStateNormal];
[btnProviderBio setTitle:[NSString stringWithFormat:@"%@ - %@", rec.providerName, rec.facilityName] forState:UIControlStateNormal];
[btnProviderBio setFrame: CGRectMake(13.0, yValue, [UIScreen mainScreen].bounds.size.width-26, 40.0)];
[btnProviderBio addTarget:self action:@selector(providerAlertDiaglog:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnProviderBio];
}
else{
lblFacilityProvider = [[UILabel alloc] init];
[lblFacilityProvider setFont:[UIFont systemFontOfSize: 14]];
[lblFacilityProvider setText:[NSString stringWithFormat:@"%@ - %@", rec.providerName, rec.facilityName]];
[lblFacilityProvider setFrame: CGRectMake(13.0, yValue, [UIScreen mainScreen].bounds.size.width-26, 40.0)];
[self.view addSubview:lblFacilityProvider];
}
I get the below result now. No label text and the button at random places. I would like for the button to be on the left with the text on the right.