Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The UITextField can't show the whole code file #32

Open
Desgard opened this issue Jan 19, 2018 · 12 comments
Open

The UITextField can't show the whole code file #32

Desgard opened this issue Jan 19, 2018 · 12 comments
Assignees

Comments

@Desgard
Copy link

Desgard commented Jan 19, 2018

In your demo, the Maxima file:

/* Maxima computer algebra system */

/* symbolic constants */

[true, false, unknown, inf, minf, ind,
 und, %e, %i, %pi, %phi, %gamma];

/* programming keywords */

if a then b elseif c then d else f;
for x:1 thru 10 step 2 do print(x);
for z:-2 while z < 0 do print(z);
for m:0 unless m > 10 do print(m);
for x in [1, 2, 3] do print(x);
foo and bar or not baz;

/* built-in variables */

[_, __, %, %%, linel, simp, dispflag,
 stringdisp, lispdisp, %edispflag];

/* built-in functions */

[sin, cosh, exp, atan2, sqrt, log, struve_h,
 sublist_indices, read_array];

/* user-defined symbols */

[foo, ?bar, baz%, quux_mumble_blurf];

/* symbols using Unicode characters */

[Љ, Щ, щ, Ӄ, ЩЩЩ, ӃӃЉЉщ];

/* numbers */

ibase : 18 $
[0, 1234, 1234., 0abcdefgh];
reset (ibase) $
[.54321, 3.21e+0, 12.34B56];

/* strings */

s1 : "\"now\" is";
s2 : "the 'time' for all good men";
print (s1, s2, "to come to the aid",
  "of their country");

/* expressions */

foo (x, y, z) :=
  if x > 1 + y
    then z - x*y
  elseif y <= 100!
    then x/(y + z)^2
  else z - y . x . y;

But in the demo, your UITextField can't show all the letters:

img_57f9ac6633c7-1

@raspu
Copy link
Owner

raspu commented Jan 19, 2018

Wierd, I'll take a look at it, but must probably is an issue in the demo, not in the library.

@raspu raspu self-assigned this Jan 19, 2018
@Desgard
Copy link
Author

Desgard commented Jan 19, 2018

@raspu I kill the app, and restart. It go back to normal. 🤣
I will try to find the problem, again.....

@raspu
Copy link
Owner

raspu commented Jan 19, 2018

Lol, let me know if you can reproduce it again.

@Desgard
Copy link
Author

Desgard commented Jan 19, 2018

It's a very very strange question.

In the demo, if you choose the device to iPhone 8 and iPhone X in .xib file, the code will be less than the origin code.

WTF!!! The bad apple.....😓

@JosephShenton
Copy link

I have this issue as well

@JosephShenton
Copy link

I fixed it with the following code

let layoutManager = NSLayoutManager()
textStorage.addLayoutManager(layoutManager)

var file = UserDefaults.standard.string(forKey: "currentFile")

let token = file?.components(separatedBy: "Documents/")

file = token?[1]

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
   
   let fileURL = dir.appendingPathComponent(file!)
   
   //reading
   do {
       code = try String(contentsOf: fileURL, encoding: .utf8)
   }
   catch { NSLog("some error")}
}

let textContainer = NSTextContainer(size: code.height(withConstrainedWidth: viewPlaceholder.frame.size.width, font: UIFont.systemFont(ofSize: 35.0)))
layoutManager.addTextContainer(textContainer)

extension String {
    func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGSize {
        let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
        let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [.font : font], context: nil)
        
        return boundingBox.size
    }
    
    func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
        let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
        let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [.font : font], context: nil)
        
        return ceil(boundingBox.width)
    }
}

@JosephShenton
Copy link

You can see it used and working in this app

Phantom HTTP by JJS Digital Pty Ltd
https://itunes.apple.com/au/app/phantom-http/id1335468125?mt=8

@raspu
Copy link
Owner

raspu commented Jan 24, 2018

Thank you @JosephShenton I will try to fix it later today using your code.

@Desgard
Copy link
Author

Desgard commented Jan 29, 2018

@JosephShenton I use your code to solve this problem. And I found your way is to change the textContainer's height dynamically.
And now, I wanted to achieve an effect, which needs to keep one line code to show in one line (not wrap automatically). And by your way, I calculate the Text Height - (Font Size + Line Interval) * Lines, but it still wrapped automatically..😭
So, is there any ideas? Thx.

@JosephShenton
Copy link

Disable text wrapping on the textview maybe?

@cntrump
Copy link

cntrump commented Jul 9, 2018

tested #52

the key:
let textContainer = NSTextContainer()
also iOS demo

@steve-taylor
Copy link

Disable text wrapping on the textview maybe?

@JosephShenton after a lot of searching, it look like disabling text wrapping in UITextView is impossible. But if you know otherwise, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants