Lozo Lozo - 1 year ago 84
Objective-C Question

How to loop through UIButtons with only certain border colors?

I am trying to loop through certain

s with only certain border colors. For example, I am looking to loop through
s that are only currently showing the border color light gray. I understand how to loop through all buttons in a view like this:

for (_buttonField in self.view.subviews)

But I cannot figure out how to only select
s that are only currently bordered with the light gray color(or any specific color for that matter). I then want to delete these UIButtons with this specified UIColor border. I know this is done with removefromsuperview, but I am not sure what to call prior to that. I am actually trying to do this when I press a 'Delete' button in a UIAlertController.

Answer Source

You have to compare the colors using isEqual since you do not want to compare pointers but the color values.

for (UIButton *button in self.view.subviews) {
    if ([[UIColor colorWithCGColor:button.layer.borderColor] isEqual:[UIColor lightGrayColor]]) {
        [button removeFromSuperview];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download