@Enez-Houad Eureka (main problem was the Attribute key name: NSParagraphStyle without AttributeName (found here after hours...)
Last part of the script, only for the fun, tap on the red rectangle
import ui
from objc_util import *
tv = ui.TextView()
tv.frame =(0,0,500,500)
tvo = ObjCInstance(tv)
NSMutableParagraphStyle = ObjCClass('NSMutableParagraphStyle').alloc()
NSMutableParagraphStyle.setLineSpacing_(20.0)
NSMutableAttributedString = ObjCClass('NSMutableAttributedString').alloc().initWithString_('test\nabcde')
NSMutableAttributedString.setAttributes_range_({'NSParagraphStyle':NSMutableParagraphStyle},NSRange(0,10))
tvo.attributedText = NSMutableAttributedString
tv.present('sheet')
# just to show line height
txt = 'test'
i = tv.text.find(txt)
p1 = tvo.positionFromPosition_offset_(tvo.beginningOfDocument(), i)
p2 = tvo.positionFromPosition_offset_(tvo.beginningOfDocument(), i+len(txt))
rge = tvo.textRangeFromPosition_toPosition_(p1,p2)
rect = tvo.firstRectForRange_(rge) # CGRect
x,y = rect.origin.x,rect.origin.y
w,h = rect.size.width,rect.size.height
#print(x,y,w,h)
l = ui.Button()
l.frame = (x,y,w,h)
l.background_color = (1,0,0,0.5)
l.border_width = 1
def button_action(sender):
if l.background_color == (1,0,0,0.5):
sender.background_color = (0,0,1,0.5)
else:
sender.background_color = (1,0,0,0.5)
l.action = button_action
tv.add_subview(l)