Now What?

We now know what view we need to hook, so make a new project using Theos following the steps in the previous tutorial and load Tweak.xm into your text editor. We need to hook CCUIControlCenterButton and so I add the following to the tweak.xm.

%hook CCUIControlCenterButton %end

Then in that hook I add:

-(void)layoutSubviews

All UIViews have a layoutSubviews method and that method is called whenever a view gets updated. UIViews also have a backgroundColor property which allows you to set the background colour of that view. So to make it chose a random colour I add after the %orig which is essential.

NSInteger randomRed = arc4random()%255; NSInteger randomGreen = arc4random()%255; NSInteger randomBlue = arc4random()%255; self.backgroundColor = [UIColor colorWithRed:randomRed/255.0f green:randomGreen/255.0f blue:randomBlue/255.0f alpha:1.0f];

This may look a little complicated so let’s run through it. First off we call the original Apple code, we don’t want to stop the buttons being a button. Then we create 3 random numbers between 0 and 255, the standard values for a RGB colour, then we create a UIColor using the colorWithRed:green:blue:alpha method which allows us to create any colour we want, we then set the background colour to be that random color.

The colour will be regenerated every time layoutSubviews is called so all the buttons should be different. This code should compile file so run make package install and let it do it’s thing.

Once Theos has installed the tweak onto your device you should see that the control center buttons are all different colours.

And thats it! We made a tweak using FLEXible and Theos!