Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add button icons to custom keyboard iOS 8?

I am creating custom keyboard for ios 8. Creating keyboard buttons like this

    UIButton *aBtn = [ UIButton buttonWithType:UIButtonTypeCustom ];

    [aBtn setFrame:CGRectMake(x, 30, btnWidth, btnHeight)];

    [aBtn setImage:[UIImage imageNamed:@"A"] forState:UIControlStateNormal];

    [aBtn setTitle:@"A" forState:UIControlStateNormal];
    [aBtn setTitleColor:[ UIColor blackColor] forState:UIControlStateNormal];
    [aBtn setTitleColor:[ UIColor whiteColor] forState:UIControlStateHighlighted];
    [aBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:aBtn];

My problem is that the image is not set to button. How can I solve this?

Do I need any special steps to be able to add images to Xcode for custom keyboards?

like image 778
Anbu Raj Avatar asked Jan 09 '23 18:01

Anbu Raj


1 Answers

You probably didn't add the image to your keyboard target.

Check your keyboard target > Build Phases > Copy bundle resources to make sure that the image is there. Drag it there if it isn't.

Note that I am talking about the keyboard target, not the host app. That could be the confusion here.

like image 162
honcheng Avatar answered Jan 12 '23 07:01

honcheng