2

It's been over a year looking for an answer to this, How can you add matching-style button to the same area/handler for those buttons

  • Do i need to re-style it to match
  • Do i need to manually set position for the new button ?

An example for cydia tweak " Safari Download Manager "

Before :

enter image description here

After :

enter image description here

You can see in order to add a new button, the current/old buttons align/position had to be changed to something smaller,

  • Do i have to manually do this ?

I'm not highly experienced with objective-c but to re-image what I'm saying in HTML :

As example, those area buttons handler :

<div id="buttons" class="top-buttons">
  <img src="back.png" >
  <img src="forth.png" >
</div>

For HTML if i want to add same button style matching the top-buttons class, All i need to do is add a new tag inside the div

Is this how Objective-C ( Or theos ) works ?

Note that it can be anything other than buttons, as example in second photo to add a new manual download row.. Etc

Osa
  • 1,922
  • 7
  • 30
  • 51

3 Answers3

2

Disclaimer: This was done using an iPhone 5 with iOS 6.1.4.

If you dump headers from Safari, you can find two potentially useful classes to look into:

BrowserToolbar:
@interface BrowserToolbar : UIToolbar <WebBookmarksClientDelegateProtocol> { id<BrowserPanel> _browserPanel; NSArray *_defaultToolbarItems; SpacedBarButtonItem *_backItem; SpacedBarButtonItem *_forwardItem; SpacedBarButtonItem *_actionItem; SpacedBarButtonItem *_bookmarksItem; SpacedBarButtonItem *_cloudTabsItem; SpacedBarButtonItem *_tabExposeItem; SpacedBarButtonItem *_fullscreenItem; BOOL _showingCloudTabButton; ... } ... - (void)_updateFixedSpacing; - (void)updateButtonsAnimated:(BOOL)animated; ... @end

and SpacedBarButtonItem:
@interface SpacedBarButtonItem : UIBarButtonItem { UIBarButtonItem *_precedingFixedSpace; } @property(readonly, assign, nonatomic) UIBarButtonItem *precedingFixedSpace; @end

Using cycript, you can see that BrowserToolbars have an _items ivar, but it is an inmutable NSArray. However, it might be possible to swap it for another array containing the original set of SpacedBarButtonItem plus your custom ones.

uroboro
  • 291
  • 2
  • 6
  • This makes a lot of sense, I would like to see a full example of a tweak doing this including adding button action to the new added button, Do you know any open source tweak that does the same thing ? – Osa Jul 07 '14 at 17:43
  • 1
    I do not know of any tweak besides SDM, which I guess isn't open source. You can try looking in the [iPhoneDevWiki page on Open Source projects](http://iphonedevwiki.net/index.php/Open_Source_Projects), but I don't recall any of them implementing this – uroboro Jul 08 '14 at 02:46
1

I'm not sure what you mean by applying the same style to each button. Those buttons are all images which is why they look similar. Their alignment and positions are also not changing when a new button gets added. Only the URL textbox gets smaller. iOS does not have a markup language for layout but you can still achieve this same effect with AutoLayout.

  1. Add every button that you want inside a UIView. Each one should have the same trailing space constraint value to the control on its right.
  2. If a button is not shown, set hidden=true but you also have to resize its trailing constraint so that the rest of the controls will shift over properly.
  3. Add another UIView to the right of the button container's view. This one you simply want to take up all remaining space so pin align this one to both ends.

As an example for step #2:

self.myBtn.hidden = true;
self.myBtnConstraint.constant = 0.0f;
Oren
  • 5,055
  • 3
  • 34
  • 52
1

When dealing with navigation bars and toolbars, You usually use a flexible-space bar button item between each "real" bar button item to space them evenly. If you insert another button item (as well as adding one more flexible-space item) will automatically reduce the space of all flexible-space items to again have an even spacing.

If you are doing it manually for other view hierarchy, you need to do the math by yourself, or use autolayout to implement the flexible width.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195