Thanks to zrzka for a working solution!
I functionized his answer here:
def superscript(view, itemName, text, size, offset, startPos, length):
#Get the UI object by name from the current UI view
target_ui_item = view[itemName]
#Create a obj-c Mutable Attributed String object and initialize with text
NSMutableAttributedString = ObjCClass('NSMutableAttributedString')
attributed_string = NSMutableAttributedString.alloc().initWithString_(ns(text))
range = NSRange(startPos, length)
#Create an obj-c Font
UIFont = ObjCClass('UIFont')
#Define a List (?) of attributes
attributes = {
ns('NSFont'): UIFont.systemFontOfSize(size),
ns('NSBaselineOffset'): ns(offset)
}
#Set the specific attributes of a specific range of the NS Mutable Attributed String
attributed_string.setAttributes_range_(attributes, range)
#
ui_item_objc = ObjCInstance(target_ui_item)
UIButton = ObjCClass('UIButton')
for subview in ui_item_objc.subviews():
if subview.isKindOfClass(UIButton):
subview.setAttributedTitle_forState_(attributed_string, 0)
Into this function, you should pass your current UI.View containing the UI element (in my case a button) which you want the superscripted string.
The second argument is the name of the UI element, in my case 'x_squared' <- the name of my button
The third argument is the text string that you want printed, in my case 'x2'
The fourth argument is the font size of the base character (I used 16)
The fifth arg is the offset for how high (or low, use negative) to offset the smaller character (I used 8)
The sixth arg is the string position to start the superscript string, (for me that was char 1)
The final arg is the length of the superscripted string (also 1 for me)
So the final call to this function looked like this (see first line below)
The second line below did a log base 10 string (slightly more complex call than an "x squared" button
superscript(self, 'x_squared', 'x2', 16, 8, 1, 1)
superscript(self, 'log_base_ten', 'log10', 16, -10, 3, 2)
Hope this helps anyone who might need this in the future!
Thanks to everyone who helped me!